在TabActivity中控制Tab的颜色状态/大小?

| 好的,这让我发疯了-我搜索了所有可以找到的参考资料和示例,但我似乎仍然缺少真正明显的东西。这些是7天电视指南的标签(显然,通常不带红色箭头的是:))... 我需要知道的是构成Tab本身的主体/背景的对象(我认为是View还是Drawable)? (如红色箭头所示),以及如何访问它或让它自动将其状态颜色更改为我选择的列表?另外,如何获取指示器TextView的状态颜色以适应呢? 示例:在上面的截图中,它是可读的,因为我已将textColor设置为静态灰色(而不是在选定选项卡上消失的亮白色)。但我希望它自动在白色选项卡上变为黑色文本(选中),并在黑色上变为亮白色文本(未选中)。 感谢所有的帮助。     
已邀请:
表示每个标签的视图可以使用
setIndicator(View)
我一直在使用以下代码来构建每个标签:
View view = buildTabView(this, \"Friday\");
TabHost.TabSpec spec = tabHost.newTabSpec(\"cat1\").setIndicator(view).setContent(intent);
tabHost.addTab(spec);

public static LinearLayout buildTabView(Context context, String label){
    LayoutInflater li = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);          
    final LinearLayout ll = (LinearLayout)li.inflate(R.layout.tab, null);

    // the following lines will change the tabs size depending on the label (text) length.
    // the longer tab text - the wider tabs
    LinearLayout.LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, label.length() + 1);
    ll.setLayoutParams(layoutParams);

    final TextView tv = (TextView)ll.findViewById(R.id.tab_tv);         
    tv.setOnTouchListener(new OnTouchListener() {               
        public boolean onTouch(View v, MotionEvent event) {
            ll.onTouchEvent(event);
            return false;
        }
    });

    tv.setText(label);          
    return ll;
}
这是layout / tab.xml
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<LinearLayout
  xmlns:android=\"http://schemas.android.com/apk/res/android\"
  android:layout_width=\"wrap_content\"
  android:layout_height=\"wrap_content\"
  android:background=\"@drawable/tab_bg_selector\"
  android:clickable=\"true\"
  >

  <TextView
  android:id=\"@+id/tab_tv\"
  android:layout_width=\"wrap_content\"
  android:layout_height=\"33dip\"
  android:text=\"Text 1\"
  android:textStyle=\"bold\"
  android:textSize=\"16dip\"
  android:gravity=\"center\"
  android:textColor=\"@drawable/tab_color_selector\"
  android:layout_weight=\"1.0\"
  android:clickable=\"true\"
  />

</LinearLayout>
请注意,LinearLayout的背景上有一个选择器(显然是要更改背景):,而TextView的textColor上有一个选择器(当选中/按下等时可以更改文本颜色)。这样,您可以在按下Tab时使文本显示为黑色,而在不按Tab时使文本显示为:)     
请使用您使用的代码更新您的问题。.您是否在可绘制对象内部使用xml来为标签设置动画?这是使用xml处理选项卡的示例。
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<selector xmlns:android=\"http://schemas.android.com/apk/res/android\">
    <!-- When selected, use grey -->
    <item android:drawable=\"@drawable/ic_tab_about_grey\"
          android:state_selected=\"false\" />
    <!-- When not selected, use white-->
    <item android:drawable=\"@drawable/ic_tab_about_color\" android:state_selected=\"true\"/>
</selector>
使用此xml文件自定义选项卡行为和图标。 以下是在标签中设置此动画/自定义选项的代码:
intent = new Intent().setClass(this, sms.class);
spec = tabHost.newTabSpec(\"sms\").setIndicator(\"SMS\",
       res.getDrawable(R.drawable.ic_tab_sms))
       .setContent(intent);
tabHost.addTab(spec);
现在,布局中的XML定义了tab-host和tab-widget。
<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\">
        <TabWidget
            android:id=\"@android:id/tabs\"
            android:layout_width=\"fill_parent\"
            android:layout_height=\"wrap_content\"
            />
</TabHost>
使用您自己的颜色,字体和结构自定义此xml布局。     

要回复问题请先登录注册