別の方法でテキストの色を変更しようとしましたが、TabWidget
成功しませんでした(以下のコードを参照)。
私の背景タブは画像です:
for (int i = 0; i < tabHost.getTabWidget().getTabCount(); i++) {
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.TRANSPARENT);
}
これが私が今やりたいことと何らかの矛盾を引き起こすかどうかはわかりません。
解決策1:
main.xml
....
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/tabbarbackground"
android:tabStripEnabled="false"
style="@style/TabText"
/> ....
style.xml
... <style name="TabText">
<item name="android:textColor">@color/tab_text_color</item> </style> ....
tab_text_color.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:textColor="#2daed9" />
<item android:state_selected="false" android:color="#FFFFFF" />
</selector>
解決策2
for (int i = 0; i < tabHost.getTabWidget().getTabCount(); i++) {
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.TRANSPARENT);
RelativeLayout rl = (RelativeLayout) tabHost.getTabWidget().getChildAt(i);
TextView textView = (TextView) rl.getChildAt(1);
textView.setTextColor(R.color.tab_text_color);
}
tab_text_color.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:textColor="#2daed9" />
<item android:state_selected="false" android:color="#FFFFFF" /> </selector>
しかし、どちらの解決策も機能しません。
ただし、2番目のソリューションを変更すると
textView.setTextColor (R.color.tab_text_color);
に
textView.setTextColor (Color.parseColor ("# ...."));
このソリューションをクリックしてもテキストの色が変わらないことを除けば、機能します。
ありがとう。