TabHost每个选项卡的字体颜色怎么修改?

编程有钱人了 2012-12-22 05:48:38

TabHost每个选项卡的字体颜色怎么修改?
默认是白色 的啊 求怎么修改

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
tools:context=".RadioActivity"
android:textColor="#000000" >

<TabHost
android:id="@+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textColor="#000000">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:textColor="#000000" >

<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
android:textColor="#000000">



android:textColor="#000000" 什么地方都设置了 没效果
...全文
223 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Ada168855 2012-12-23
  • 打赏
  • 举报
回复
应该可以改吧,是不是什么地方错了
Jobernowl 2012-12-23
  • 打赏
  • 举报
回复
引用 3 楼 wlianghe00 的回复:
Java code?1234567for(int i = 0; i < tabWidge.getChildCount(); i++) { final TextView tv = (TextView) tabWidge.getChildAt(i).findViewById(android.R.id.title); tv.setTextColor(Color.WH……
这个方法存在兼容性问题吧 如果有的系统把这个id给修改了不就报空指针了么
Utopia 2012-12-22
  • 打赏
  • 举报
回复

for(int i = 0; i < tabWidge.getChildCount(); i++) { 

  final TextView tv = (TextView) tabWidge.getChildAt(i).findViewById(android.R.id.title); 
   tv.setTextColor(Color.WHITE);   
   tv.setTextSize(18);  

}
Jobernowl 2012-12-22
  • 打赏
  • 举报
回复
indicator.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/indicator_bg"
    android:gravity="center" >

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:gravity="center"
        android:textAppearance="@android:style/TextAppearance.Medium"
        android:textColor="#FFFFE7" />

</LinearLayout>
music_explorer.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:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <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="0.0dip"
            android:layout_weight="1.0" />
    </LinearLayout>

</TabHost>
activity

@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.music_explorer);
    li=getLayoutInflater();
    initTabs();
  }
  
  private void initTabs(){
    TabHost th=getTabHost();
    th.setOnTabChangedListener(this);
    TabSpec ts = null;
    int count = 4;
    if(artist_key.length()>0){
      count = 2;
    }
    for(int i=0;i<count;i++){
      ts=th.newTabSpec(tags[i]);
      View view=li.inflate(R.layout.indicator, null);
      TextView tv=(TextView) view.findViewById(R.id.textView);
      tv.setText(getString(tabsResources[i]));
      ts.setIndicator(view);
      ts.setContent(this);
      th.addTab(ts);
    }
  }

Jobernowl 2012-12-22
  • 打赏
  • 举报
回复
这里有一个简单的项目 里面有修改tab字体颜色的AndroidMusicPlayer

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧