Android中自定义tabhost的TAB页面被选中时TAB底部的颜色

系统的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>

效果如下:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值