の断片に異なるテーマを適用します。アンドロイド:私は何をしたいか一つの活性
を私はアクションバーがに応じて、異なる背景色を持っているように、私のMainActivityの各フラグメントは、別のテーマを使用したいです可視フラグメント。
状況:
私はタブ+スワイプナビゲーションを使用していますMainActivityを作成しました。私は7つのタブ(= 7つのフラグメント)を追加しました。最初のフラグメント(fragment_main_1)にのみ適用する必要があるテーマを1つ作成しました。ここ
テーマ:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Blue" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">@style/Blue.ActionBarStyle</item>
</style>
<style name="Blue.ActionBarStyle" parent="android:Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">@style/Blue.ActionBar.TitleTextStyle</item>
<item name="android:background">#33B5E5</item>
</style>
<style name="Blue.ActionBar.TitleTextStyle" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#FFFFFF</item>
</style>
</resources>
6つのより多くのテーマを作成した後、アクションバーは自動的に背景色を変更しながら、タブをスワイプすることが可能であるべきです。私はあなたが私を助けることができると思います
// 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);
:)ありがとう:
はFragment1.javaに(私はstackoverflowの上ここにあります)これらの行を追加:どのような動作しませんでした
。
あなたは今までに解決策を見つけますか? – jcaruso
いいえ、私はそのプロジェクトを断念しました:( – Jonas
誰でもこの質問への回答が見つかりましたか? –