TabWidget改变标签底线颜色 [英] TabWidget change tab bottom line color

查看:951
本文介绍了TabWidget改变标签底线颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变标签底线色我跟着这个步骤:结果
1.我的 styles.xml 文件我有:

I would like to change "Tab bottom line color" i followed this steps:
1. on my styles.xml file i have:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Dgrey</item>
    </style>

    <style name="ActionBarTabStyle.Dgrey" parent="@android:style/Widget.Holo.ActionBar.TabView">
        <item name="android:background">@drawable/tab_indicator_ab_dgrey</item>
    </style>

</resources>

2。在我的 tab_indicator_ab_dgrey 我有:

<?xml version="1.0" encoding="utf-8"?>

<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_dgrey" />
    <item android:state_focused="false" android:state_selected="true"  android:state_pressed="false" android:drawable="@drawable/tab_selected_dgrey" />

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

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

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

3。在我的绘制文件夹(华电国际,MDPI,xhdpi,xxhdpi)我有这些文件:结果
- tab_selected_dgrey.9.png结果
- tab_selected_focused_dgrey.9.png结果
- tab_selected_ pressed_dgrey.9.png结果
- tab_unselected_dgrey.9.png结果
- tab_unselected_focused_dgrey.9.png结果
- tab_unselected_ pressed_dgrey.9.png搜索结果
在我的文件夹绘制我有:结果
tab_indicator_ab_dgrey.xml 文件

和结尾,这是我的的manifest.xml


<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="ch.studentgrades.StudentGrades"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

我不知道为什么(我也跟着教程)当我运行应用程序并没有改变什么,耳线颜色仍为蓝色。

I don't know why (i followed the tutorial) when i run the app doesn't change anything, the tab line color remain blue.

推荐答案

这<一个href=\"http://stackoverflow.com/questions/14722654/tabwidget-current-tab-bottom-line-color\">answer解决了我的问题。

将此code你设置你的标签之后:

Add this code after you setup your tabs :

TabHost host = (TabHost)view.findViewById(R.id.tab_host);
TabWidget widget = host.getTabWidget();
for(int i = 0; i < widget.getChildCount(); i++) {
    View v = widget.getChildAt(i);

    // Look for the title view to ensure this is an indicator and not a divider.
    TextView tv = (TextView)v.findViewById(android.R.id.title);
    if(tv == null) {
        continue;
    }
    v.setBackgroundResource(R.drawable.tab_indicator_ab_dgrey);
}

然后就可以从删除以下code你的 styles.xml

<item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Dgrey</item>

<style name="ActionBarTabStyle.Dgrey" parent="@android:style/Widget.Holo.ActionBar.TabView">
    <item name="android:background">@drawable/tab_indicator_ab_dgrey</item>
</style>

这篇关于TabWidget改变标签底线颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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