我正在使用标签。我想更改标签的背景颜色或主题。当我点击选项卡时,默认颜色显示为灰色,但我想以自定义颜色显示该选项卡。
这里是我的代码:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-30dp"
android:background="#FF0000"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</FrameLayout>
</LinearLayout>
</TabHost>
类文件是
public class AndroidtabActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// View title = getWindow().findViewById(android.R.id.title);
// View titleBar = (View) title.getParent();
// titleBar.setBackgroundResource(R.drawable.top_bar2);
Resources res = getResources();
TabHost tabHost = getTabHost();
//tabHost = (TabHost) findViewById(R.id.tabhost);
tabHost.setup();
//tabHost.setBackgroundResource(R.drawable.pink);
TabHost.TabSpec spec;
//tabHost.getTabWidget().setDividerDrawable(R.drawable.top_bar);
Intent in;
in = new Intent().setClass(this, MainActivity.class);
spec=tabHost.newTabSpec("calc").setIndicator("calculate").setContent(in);
tabHost.addTab(spec);
in = new Intent().setClass(this, TutorialZoomActivity1.class);
spec=tabHost.newTabSpec("help").setIndicator("help").setContent(in);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
// spec1.setIndicator("Tab 1",getResources().getDrawable(R.drawable.flash));
}
}
请告诉我如何更改标签的背景颜色。
答案 0 :(得分:0)
也许您应该创建自定义标签。
答案 1 :(得分:0)
您可以按
更改标签背景颜色for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
tabHost.getTabWidget().getChildAt(i).
setBackgroundResource(R.drawable.hans_layout_nblue);
}