开发者

Android - Where to set the color of pressed,focused... Tabs?

开发者 https://www.devze.com 2023-01-08 11:55 出处:网络
I created a small Tab-Layout. Now how can i specify the color of the TabWidget depending on it开发者_运维知识库s state (focused,pressed..)

I created a small Tab-Layout.

Now how can i specify the color of the TabWidget depending on it开发者_运维知识库s state (focused,pressed..)

I built a new .xml, but i dont know how to set it to my Tabs:

<?xml version="1.0" encoding="UTF-8"?>
<selector
    android:id="@+id/tabSelector"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_focused="false"
        android:state_selected="false"
        android:state_pressed="true"
        android:background="#32CD32"/>  <br />
    <item
        android:state_focused="false"
        android:state_selected="true"
        android:state_pressed="false"/>
    <item
        android:state_focused="true"
        android:state_selected="false"
        android:state_pressed="false"/>
    <item
        android:state_focused="true"
        android:state_selected="true"
        android:state_pressed="false"/>
</selector>


ok your selector must be into your res/drawable folder

this is the way to set your selector to the first tab ( getChildAt(0) )

tabs = getTabHost();
...
...
...
tabs.getTabWidget().getChildAt(0).setBackgroundColor(R.drawable.my_selector);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号