Skip to content

Instantly share code, notes, and snippets.

@alexfu
Created March 3, 2015 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexfu/d2510aa3a40ef805f216 to your computer and use it in GitHub Desktop.
Save alexfu/d2510aa3a40ef805f216 to your computer and use it in GitHub Desktop.
Change View styles on the fly with ContextThemeWrapper
public class MyFragment {
private Context context;
@Override
public void onCreate(Bundle savedInstanceState) {
// Where the magic happens
context = new ContextThemeWrapper(getActivity(), R.style.Theme_Main_Inverse);
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.fragment_myprofile, container, false);
ButterKnife.inject(this, view);
bindViews();
return view;
}
}
<resources>
<style name="Theme.Main" parent="Theme.AppCompat.Light.NoActionBar"/>
<style name="Theme.Main.Inverse" parent="Theme.AppCompat.NoActionBar"/>
</resources>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment