I have been trying to edit a FragmentedTabHost's background colors to mess around with it a bit and I am quite clueless as to why I can changed the "unselected" state but not the "selected" state.
So what I have is a main drawable called "tabs" and inside I have references to two others "tab_selected" and "tab_unselected". I applied this background pretty much everywhere I could find to see if it worked but I got to the point where I think the best place to put it is in the TabWidget tag.
The selected state remains with the grayish color of the normal tab but the other one actually changes.
I don't know if I should be changing code elsewhere, as I already changed in the code it self by saying:
mTabHost.setBackgroundResource(R.drawable.tabs);
And still no progress...
Below is the code:
tabs.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://ift.tt/nIICcg">
<item android:state_selected="true"
android:drawable="@drawable/tab_selected" />
<item android:state_selected="false"
android:drawable="@drawable/tab_unselected" />
</selector>
tab_selected.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://ift.tt/nIICcg">
<item>
<shape android:shape="rectangle">
<solid android:color="#7fff00" />
</shape>
</item>
<item android:top="20dp">
<shape android:shape="rectangle">
<solid android:color="#7fff00" />
</shape>
</item>
<item android:bottom="2dp">
<shape android:shape="rectangle">
<gradient android:startColor="#7fff00"
android:endColor="#7fff00"
android:angle="270" />
<corners android:topLeftRadius="10dp" android:topRightRadius="10dp"/>
</shape>
</item>
</layer-list>
tab_unselected.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://ift.tt/nIICcg">
<item>
<shape android:shape="rectangle">
<solid android:color="#86B4CF" />
</shape>
</item>
<item android:top="20dp">
<shape android:shape="rectangle">
<solid android:color="#86B4CF" />
</shape>
</item>
<item android:bottom="2dp">
<shape android:shape="rectangle">
<gradient android:startColor="#86B4CF"
android:endColor="#6792AB"
android:angle="270" />
<corners android:topLeftRadius="10dp" android:topRightRadius="10dp"/>
</shape>
</item>
</layer-list>
And finally the FragmentedHost:
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".Home"
android:orientation="vertical"
android:background="@drawable/global_background">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_date"
style="@style/header"/>
</LinearLayout>
<android.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TabWidget
android:id="@android:id/tabs"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="@drawable/tabs"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"/>
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
No comments:
Post a Comment