Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Apply different themes to fragments of one activity
    primarykey
    data
    text
    <p><strong>What I want to do:</strong></p> <p>I want each Fragment of my MainActivity to use a different theme, so that the ActionBar has different background-colors, depending on the visible Fragment.</p> <p><strong>The Situation:</strong></p> <p>I created a MainActivity which uses the Tabs + Swipe Navigation. I Added 7 Tabs (=7 Fragments). I created one Theme which should be applied only to the first Fragment (fragment_main_1).</p> <p>Here the Theme:</p> <pre><code>&lt;resources xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;style name="Blue" parent="android:Theme.Holo.Light"&gt; &lt;item name="android:actionBarStyle"&gt;@style/Blue.ActionBarStyle&lt;/item&gt; &lt;/style&gt; &lt;style name="Blue.ActionBarStyle" parent="android:Widget.Holo.Light.ActionBar"&gt; &lt;item name="android:titleTextStyle"&gt;@style/Blue.ActionBar.TitleTextStyle&lt;/item&gt; &lt;item name="android:background"&gt;#33B5E5&lt;/item&gt; &lt;/style&gt; &lt;style name="Blue.ActionBar.TitleTextStyle" parent="android:TextAppearance.Holo.Widget.ActionBar.Title"&gt; &lt;item name="android:textColor"&gt;#FFFFFF&lt;/item&gt; &lt;/style&gt; &lt;/resources&gt; </code></pre> <p>After creating 6 more Themes it should be possible to swipe through the Tabs while the ActionBar changes its background-color automatically.</p> <p><strong>What didn't work:</strong></p> <p>Adding those lines (which I found here on stackoverflow) to the Fragment1.java:</p> <pre><code>// create ContextThemeWrapper from the original Activity Context with the custom theme final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), R.style.Blue); // clone the inflater using the ContextThemeWrapper LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper); // inflate the layout using the cloned inflater, not default inflater return localInflater.inflate(R.layout.fragment_main_1,container, false); </code></pre> <p>I hope you can help me:) Thank you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload