系统的tabost的tab底部颜色为颜色,要修改它的颜色的话,查看了系统的tabwidght的style。
<pre name="code" class="java"><style name="Widget.Holo.TabWidget" parent="Widget.TabWidget">
<item name="android:tabStripLeft">@null</item>
<item name="android:tabStripRight">@null</item>
<item name="android:tabStripEnabled">false</item>
<item name="android:divider">?android:attr/dividerVertical</item>
<item name="android:showDividers">middle</item>
<item name="android:dividerPadding">8dip</item>
<item name="android:measureWithLargestChild">true</item>
<item name="android:tabLayout">@android:layout/tab_indicator_holo</item>
</style>
<style name="Widget.TabWidget">
<item name="android:textAppearance">@style/TextAppearance.Widget.TabWidget</item>
<item name="ellipsize">marquee</item>
<item name="singleLine">true</item>
<item name="android:tabStripLeft">@android:drawable/tab_bottom_left</item>
<item name="android:tabStripRight">@android:drawable/tab_bottom_right</item>
<item name="android:tabStripEnabled">true</item>
<item name="android:divider">@null</item>
<item name="android:gravity">fill_horizontal|center_vertical</item>
<item name="android:tabLayout">@android:layout/tab_indicator</item>
</style>
各种属性的测试,只有如下代码把tab的底部颜色改掉:
tabHost = (TabHost) view.findViewById(android.R.id.tabhost);
// tabHost.setVisibility(TabHost.INVISIBLE);
tabHost.setup();
mViewPager = (ViewPager) view.findViewById(R.id.new_pager);
mTabsAdapter = new TabsAdapter(getActivity(), tabHost, mViewPager, this);
for (int i = 0; i < tabWidget.getChildCount(); i++) {
TextView tView = (TextView) tabWidget.getChildAt(i).findViewById(
android.R.id.title);
//修改背景
tabWidget.getChildAt(i).setBackgroundResource(
R.drawable.custom_tab_indicator);
tView.setTextSize(16);
//字体
tView.setTypeface(Typeface.DEFAULT);
if (tabHost.getCurrentTab() == i) {
tView.setTextColor(getResources().getColorStateList(
android.R.color.holo_green_dark));
} else {
tView.setTextColor(getResources().getColorStateList(
android.R.color.black));
}
}
//R.drawable.custom_tab_indicator
</pre><pre code_snippet_id="408259" snippet_file_name="blog_20140627_2_9365823" name="code" class="html">用到图片经过draw9处理
<?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/custom_tab_indicator_unselected" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/custom_tab_indicator_selected" />
<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/custom_tab_indicator_unselected_focused" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/custom_tab_indicator_selected_pressed" />
<!-- Pressed -->
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/custom_tab_indicator_unselected_pressed" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/custom_tab_indicator_selected_pressed" />
<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/custom_tab_indicator_unselected_pressed" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/custom_tab_indicator_selected_pressed" />
</selector>
效果如下: