Android TabWidget更改选项卡底线颜色
我想更改“选项卡底线颜色”,我遵循以下步骤:Android TabWidget更改选项卡底线颜色,android,android-tabhost,Android,Android Tabhost,我想更改“选项卡底线颜色”,我遵循以下步骤: 1.在我的style.xml文件中,我有: <resources> <!-- Base application theme. --> <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar"> <!-- Customize your theme here. --> <
1.在我的
style.xml
文件中,我有:
<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>
三,。在我的可绘制文件夹(hdpi、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
-制表符_未选中_按下_dgrey.9.png
在我的可绘图文件夹中,我有:
tab_indicator_ab_dgrey.xml
文件
manifest.xml
:
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);
}
及
@可拉拔/选项卡指示器
<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>
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);
}
<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>