【发布时间】:2011-05-21 00:20:30
【问题描述】:
我该怎么做?可能吗?
:
tabhost.getTabWidget().getChildAt(i) 。 setTextColor 还是别的什么..?
【问题讨论】:
我该怎么做?可能吗?
:
tabhost.getTabWidget().getChildAt(i) 。 setTextColor 还是别的什么..?
【问题讨论】:
我猜你可以使用 TabHost.TabSpec.setIndicator(android.view.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。祝你好运。
【讨论】:
要更改选项卡的文本颜色,您需要获取视图,即设置为选项卡标题的 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(.....);
}
希望这会有所帮助....
【讨论】: