更改tab​​host风格的Andr​​oid [英] Change the tabhost style android

查看:179
本文介绍了更改tab​​host风格的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要的tabhost的默认蓝色变为红色。

 <样式名称=AppTheme父=机器人:Theme.Light.NoTitleBar>
          <项目名称=机器人:tabWidgetStyle> @绘制/ tab_indicator_holo< /项目>
          < /风格>

tab_indicator_holo.xml

 <选择的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <! - 非重点国家 - >
    <项目的android:state_focused =false的机器人:state_selected =false的机器人:STATE_ pressed =false的机器人:可绘制=@绘制/ tab_unselected_holo/>
    <项目的android:state_focused =false的机器人:state_selected =真正的机器人:STATE_ pressed =false的机器人:可绘制=@绘制/ tab_selected_holo/>    <! - 聚焦美国 - >
    <项目的android:state_focused =真正的机器人:state_selected =false的机器人:STATE_ pressed =false的机器人:可绘制=@绘制/ tab_unselected_focused_holo/>
    <项目的android:state_focused =真正的机器人:state_selected =真正的机器人:STATE_ pressed =false的机器人:可绘制=@绘制/ tab_selected_focused_holo/>    <! - pressed - >
    <! - 非重点国家 - >
    <项目的android:state_focused =false的机器人:state_selected =false的机器人:STATE_ pressed =真正的机器人:可绘制=@绘制/ tab_unselected_ pressed_holo/>
    <项目的android:state_focused =false的机器人:state_selected =真正的机器人:STATE_ pressed =真正的机器人:可绘制=@绘制/ tab_selected_ pressed_holo/>    <! - 聚焦美国 - >
    <项目的android:state_focused =真正的机器人:state_selected =false的机器人:STATE_ pressed =真正的机器人:可绘制=@绘制/ tab_unselected_ pressed_holo/>
    <项目的android:state_focused =真正的机器人:state_selected =真正的机器人:STATE_ pressed =真正的机器人:可绘制=@绘制/ tab_selected_ pressed_holo/>
< /选择>

但标签样式不应用于tabhost。默认的蓝色是不是变成红色。

我得到这个

任何意见或建议,请。


解决方案

您可能已经找到了答案,但对于那些谁可能面临同样的问题,这是我做了什么。


  1. 定制全息主题并设置tabwedget为yes,并选择preferred颜色。


  2. 下载zip,复制到我的项目。


  3. 添加与充气tab_indicator_holo创建的视图来tabadapter。


 查看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,空);    查看mIndicator2 = inflater.inflate(R.layout.tab_indicator_holo,mTabHost.getTabWidget(),FALSE);
    TextView的标题2 =(TextView中)mIndicator2.findViewById(android.R.id.title);    title2.setText(TAB2);
    mTabsAdapter.addTab(mTabHost.newTabSpec(TAB2)setIndicator(mIndicator2),FRAGMENT2.class,空);

I want to change the default blue color of the tabhost to red.

<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>

But the tab style is not applied to the tabhost. The default blue color is not changed to red.

I am getting this

Any ideas or suggestions please.

解决方案

You might have already found the answer, but for those who may face the same problem, Here is what I have done.

  1. go to custom holo theme and set tabwedget to yes and choose preferred color.

  2. Download the zip, copy over to my project.

  3. Add to tabadapter with the view created by inflating tab_indicator_holo.

    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);

这篇关于更改tab​​host风格的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆