何をしたかはわかりませんが、しばらくの間、TabWidget には非常に見栄えのする白いタブがありました。プロジェクトでテーマや背景色/前景色をまったく設定しませんでした。次回コンパイルすると、灰色のタブに戻りました。私のアプリケーションはデフォルトのダーク テーマを使用しています。アプリケーションのテーマをライトに設定しても、タブは灰色のままです。明らかに、タブの色を変更したのは別の何かでした。誰でもこれを行う方法を知っていますか?
11629 次
4 に答える
14
Android 1.6 のライト テーマ (タブ インジケーターのテキストが白) のバグが原因で問題が発生していました。次のように、デフォルトのテーマをオーバーライドできました。
- デフォルトのテーマから継承したカスタム テーマを作成しました。
styles.xml
:
<style name="MyTheme" parent="@android:style/Theme.Light">
<item name="android:tabWidgetStyle">@style/LightTabWidget</item>
</style>
<style name="LightTabWidget" parent="@android:style/Widget.TabWidget">
<!-- set textColor to red, so you can verify that it applied. -->
<item name="android:textColor">#f00</item>
</style>
次に、 my の要素に追加android:theme="@style/MyTheme"
して、そのテーマをアプリケーションに適用します。<application />
AndroidManifest.xml
于 2010-07-02T14:33:40.840 に答える
6
私のこの答えを確認してください:タブウィジェットの背景はスケーリングを無視します
android.graphics.drawable
パッケージを参照することもできます
コードでは、次のようにタブの背景を設定できます。
tabHost.getTabWidget().getChildAt(0).setBackgroundResource(
android.R.color.white);
于 2010-03-30T09:00:03.373 に答える
1
の中にpublic void onCreate(Bundle savedInstanceState)
`tabHost = getTabHost();
tabHost.setOnTabChangedListener(this);
tabHost.setCurrentTab(0);
setTabColor();`
リスナーよりも:
public void onTabChanged(String tabId) { setTabColor();
最後に、フォアグラウンドとバックグラウンドも設定する関数:
public void setTabColor() {
// set foreground color:
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
RelativeLayout rl = (RelativeLayout) tabHost.getTabWidget().getChildAt(i);
ImageView imageView = (ImageView) rl.getChildAt(0);// change it if you want it
TextView textView = (TextView) rl.getChildAt(1);//
textView.setTextColor(Color.parseColor("#FFFFFF"));
}
// set background color:
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#010101")); // unselected
}
tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#121288")); // selected
}
于 2011-07-20T11:34:32.920 に答える
0
onCreated() で:
tabHost.setCurrentTab(0);
// Set tabs text color to white:
TabWidget tabWidget = tabHost.getTabWidget();
int whiteColor = getResources().getColor(R.color.white);
int someOtherColor = getResources().getColor(R.color.someOtherColor);
for(int i = 0; i < tabWidget.getChildCount(); i++){
View tabWidgetChild = tabWidget.getChildAt(i);
if(tabWidgetChild instanceof TextView){
((TextView) tabWidgetChild).setTextColor(whiteColor);
} else if(tabWidgetChild instanceof Button){
((Button) tabWidgetChild).setTextColor(whiteColor);
} else if(tabWidgetChild instanceof ViewGroup){
ViewGroup vg = (ViewGroup)tabWidgetChild;
for(int y = 0; y < vg.getChildCount(); y++){
View vgChild = vg.getChildAt(y);
if(vgChild instanceof TextView){
((TextView) vgChild).setTextColor(whiteColor);
}
}
vg.setBackgroundColor(someOtherColor);
}
}
于 2013-11-01T13:30:43.653 に答える