Themes in Fragments

android, android-fragments, android-styles

Solution

Okay, i think i just might have an answer for you. In using the code you have:

ctx = new ContextThemWrapper(getActivity(), R.style.myappstyletimes);
LayoutInflater localInflater = inflater.cloneInContext(ctx);
View view = localInflater.inflate(R.layout.prayerpager, container, false);
return view;

You have to set up a custom theme that you make, as demonstrated below

<style name="myappstyletimes" parent="android:style/Theme">
    <item name="android:background">#000000</item>
    <item name="android:textColor">#ffffff</item>
</style>

This changes the background to `black` and the text to `white`.

I tested this myself, and it works.

Edit: Here are some tutorials on custom themes:

DeveloperLife

Vogella

Android Coding

Problem

Hola Stackoverflowers! i have like 10 fragments in the navigation drawer.. however i want one fragment to have a special theme, and i want the activity itself and the other fragment have the same theme. How can i achieve that? What i tried: ``` ctx = new ContextThemeWrapper(getActivity(), R.style.myappstyletimes); LayoutInflater localInflater = inflater.cloneInContext(ctx); View view = localInflater.inflate(R.layout.prayerpager, container, false); View view = localInflater.inflate(R.layout.prayerpager, container, false); return view; ``` And i also changed the context of my app to ctx... it's still the same theme presented in the manifest file ``` <activity android:theme="@style/maintheme" > ``` My Theme: ``` <style name="myappstyletimes" parent="android:Theme.Material"> <item name="android:actionBarStyle">@style/ActionBarStyle.Transparent</item> <item name="android:windowActionBarOverlay">true</item> <item name="android:colorPrimary">@android:color/transparent</item> <item name="android:colorAccent">@color/accentcolor</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowTranslucentNavigation">true</item> <item name="android:windowTranslucentStatus">true</item> </style> ``` Any Suggestions?

Original source