【问题标题】:Change the tabhost style android更改tabhost样式android
【发布时间】:2013-07-15 07:51:05
【问题描述】:

我想将 tabhost 的默认蓝色更改为红色。

<style name="AppTheme" parent="android:Theme.Light.NoTitleBar">
          <item name="android:tabWidgetStyle">@drawable/tab_indicator_holo</item>
          </style>

tab_indicator_holo.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Non focused states -->
    <item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected_holo" />
    <item android:state_focused="false" android:state_selected="true"  android:state_pressed="false" android:drawable="@drawable/tab_selected_holo" />

    <!-- Focused states -->
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected_focused_holo" />
    <item android:state_focused="true" android:state_selected="true"  android:state_pressed="false" android:drawable="@drawable/tab_selected_focused_holo" />

    <!-- Pressed -->
    <!--    Non focused states -->
    <item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_holo" />
    <item android:state_focused="false" android:state_selected="true"  android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_holo" />

    <!--    Focused states -->
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_holo" />
    <item android:state_focused="true" android:state_selected="true"  android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_holo" />
</selector>

但选项卡样式未应用于选项卡主机。默认的蓝色未更改为红色。

我收到了

请有任何想法或建议。

【问题讨论】:

  • android:tabWidgetStyle 应该指向一个扩展 Widget.TabWidget 的样式(这反过来会覆盖它的标签条属性之一以指向您拥有的 tab_indicator_holo.xml 可绘制对象)。

标签: android android-tabhost


【解决方案1】:

你可能已经找到了答案,但对于那些可能面临同样问题的人,这就是我所做的。

  1. 转到custom holo theme 并将tabwedge 设置为yes 并选择首选颜色。

  2. 下载压缩包,复制到我的项目中。

  3. 使用通过膨胀 tab_indicator_holo 创建的视图添加到 tabadapter。

    View mIndicator = inflater.inflate(R.layout.tab_indicator_holo, mTabHost.getTabWidget(), false);
    TextView title1 = (TextView) mIndicator.findViewById(android.R.id.title);

    title1.setText("TAB1");

    mTabsAdapter.addTab(mTabHost.newTabSpec("TAB1").setIndicator( mIndicator), FRAGMENT1.class, null);

    View mIndicator2 = inflater.inflate(R.layout.tab_indicator_holo,      mTabHost.getTabWidget(), false);
    TextView title2 = (TextView) mIndicator2.findViewById(android.R.id.title);

    title2.setText("TAB2");
    mTabsAdapter.addTab(mTabHost.newTabSpec("TAB2").setIndicator(mIndicator2), FRAGMENT2.class, null);

【讨论】:

  • 谢谢!这最终正是我所需要的。太棒了!
  • NyanLH,你能完成你的代码示例吗?添加到哪个功能? inflater、mTabsAdapter 哪里来的?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-02-16
  • 2014-07-22
  • 1970-01-01
  • 2023-01-23
  • 1970-01-01
  • 2020-03-02
  • 1970-01-01
相关资源
最近更新 更多