[英]Android change tabview's text color not backgroundcolor
我怎么能這樣做? 可能嗎?
:
tabhost.getTabWidget()。getChildAt(i)。 setTextColor或其他什么..?
要更改選項卡的文本顏色,您需要獲取視圖,即設置為選項卡標題的TextView,您可以像這樣更改它:
TabHost tabhost = getTabHost();
for(int i=0;i<tabhost.getTabWidget().getChildCount();i++)
{
TextView tv = (TextView) tabhost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
tv.setTextColor(.....);
}
希望這可以幫助....
我想你可以使用TabHost.TabSpec.setIndicator(android.view.View視圖 )根據你的需要傳遞配置(着色)的TextView
。
但是我再一次重讀了你的帖子 - 可能你的意思是如何改變標簽內容的顏色,而我正在談論標簽標簽......如果是這種情況,我很抱歉,請忽略這個答案。
更新 :
在布局xml中做到最舒服:
<?xml version="1.0" encoding="utf-8"?>
<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">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a tab - RED"
android:textColor="#FF0000" />
<TextView
android:id="@+id/textview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is another tab - GREEN"
android:textColor="#00FF00" />
<TextView
android:id="@+id/textview3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a third tab - BLUE"
android:textColor="#0000FF" />
</FrameLayout>
</LinearLayout>
</TabHost>
嘗試ColorStateLists 。 祝好運。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.