Android でより複雑なテーマ/スタイルの状況を実装する方法を理解するのに苦労しています。
Android で提供されているさまざまなスタイリング/テーマのチュートリアルを調べましたが、私の場合は当てはまりません。
(抽出された) 状況は次のとおりです。カスタムの tabwidgetを使用してアプリケーションを作成しており、アプリケーションをさまざまなスタイル(テーマ)でブランド化できるようにする必要があります。
tabwidget の XML ( http://joshclemm.com/blog/?p=136に基づく):
レイアウト/tabs_bg.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabsLayout" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="@drawable/tab_bg_selector"
android:padding="10dip" android:gravity="center" android:orientation="vertical">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:orientation="horizontal"
android:gravity="center">
<ImageView
android:src="@drawable/star_fav_empty"
android:layout_height="24px"
android:layout_width="24px"
android:id="@+id/tabsImage"
android:paddingRight="5dip"></ImageView>
<TextView
android:id="@+id/tabsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hallowaaaaa"
android:textSize="15dip"
android:textColor="?android:textColorTertiary"/>
</LinearLayout>
</LinearLayout>
drawable/tab_bg_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Active tab -->
<item android:state_selected="true" android:state_focused="false"
android:state_pressed="false" android:drawable="@drawable/tab_bg_selected" />
<!-- Inactive tab -->
<item android:state_selected="false" android:state_focused="false"
android:state_pressed="false" android:drawable="@drawable/tab_bg_unselected" />
<!-- Pressed tab -->
<item android:state_pressed="true" android:state_enabled="false" android:drawable="@android:color/transparent" />
<!-- Selected tab (using d-pad) -->
<item android:state_focused="true" android:state_selected="true"
android:state_pressed="false" android:drawable="@android:color/transparent" />
</selector>
drawable/tab_bg_selected.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#A8A8A8" android:centerColor="#7F7F7F"
android:endColor="#696969" android:angle="-90" />
</shape>
drawable/tab_bg_unselected.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#5C5C5C" android:centerColor="#424242"
android:endColor="#222222" android:angle="-90" />
</shape>
次に、次のようにスタイルを定義したいと思います。
値/MyBaseStyle.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyBaseStyle" parent="@android:style/Theme.Light">
</style>
</resources>
値/MySubStyle1.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MySubStyle1" parent="MyBaseStyle">
</style>
</resources>
値/MySubStyle2.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MySubStyle2" parent="MyBaseStyle">
</style>
</resources>
ここでの大きな疑問は次のとおりです。
1. MyBaseStyle.xml にグラデーションまたは色を配置し、ハードコードされたグラデーション/色の代わりに tab_bg_selected.xml および tab_bg_unselected.xml 内で使用するにはどうすればよいですか?
2. MySubStyle1.xml および MySubStyle2.xml 内から MyBaseStyle.xml で定義したグラデーション/カラーをそれぞれオーバーライドして、カスタム タブウィジェットがそれに応じてスタイル設定されるようにするにはどうすればよいですか?
備考: 「スタイリング」を維持できるように、(複数の異なる XML ファイル内で複数の異なる色を定義するのではなく) MyBaseStyle.xml、MySubStyle1.xml、および MySubStyle2.xml でそれぞれグラデーション/色を定義できるようにしたいと考えています。 1つのファイル内。そうすれば、アプリケーションのブランディングを外部委託できます。
誰かがこれを達成するのを手伝ってもらえますか?