我需要我的TabHost看起来像第一个。 Corner的Xml文件代码为:
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<shape android:shape="rectangle">
<corners
android:topLeftRadius="10dp"
android:bottomLeftRadius="10dp"/>
<gradient
android:startColor="#88a9a9a9"
android:endColor="#000"
android:gradientRadius="400"
android:angle="270"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<gradient
android:angle="90"
android:startColor="#880f0f10"
android:centerColor="#8858585a"
android:endColor="#88a9a9a9"/>
<corners
android:topRightRadius="10dp"
android:bottomLeftRadius="10dp"/>
</shape>
</item></selector>
Java代码行:
mTabHost.getTabWidget()getChildAt(0).setBackgroundResource(R.drawable.roundcorner);`
答案 0 :(得分:2)
试试这种方式, 左侧第一个: -
<item android:state_selected="true">
<shape android:shape="rectangle">
<corners
android:topLeftRadius="5dp"
android:bottomLeftRadius="5dp"/>
<gradient
android:startColor="#880f0f10"
android:endColor="#000"
android:gradientRadius="400"
android:angle="-270"/>
<stroke android:width="3px" android:color="@color/black" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<gradient
android:angle="90"
android:startColor="#CCCCCC"
android:centerColor="#CCCCCC"
android:endColor="#CCCCCC"/>
<corners
android:topLeftRadius="5dp"
android:bottomLeftRadius="5dp"/>
<stroke android:width="5px" android:color="@color/black" />
</shape>
</item>
右侧最后一个: -
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<shape android:shape="rectangle">
<corners
android:topRightRadius="5dp"
android:bottomRightRadius="5dp"/>
<gradient
android:startColor="#880f0f10"
android:endColor="#000"
android:gradientRadius="400"
android:angle="-270"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<gradient
android:angle="90"
android:startColor="#CCCCCC"
android:centerColor="#CCCCCC"
android:endColor="#CCCCCC"/>
<corners
android:topRightRadius="5dp"
android:bottomRightRadius="5dp"/>
<stroke android:width="5px" android:color="@color/black" />
</shape>
</item></selector>
代表中心
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<shape android:shape="rectangle">
<gradient
android:startColor="#880f0f10"
android:endColor="#000"
android:gradientRadius="400"
android:angle="-270"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<gradient
android:angle="90"
android:startColor="#CCCCCC"
android:centerColor="#CCCCCC"
android:endColor="#CCCCCC"/>
<stroke android:width="5px" android:color="@color/black" />
</shape>
</item></selector>
和Java
mTabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.roundcorner_tab_left);
mTabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.roundcorner_tab_center);
mTabHost.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.roundcorner_tab_right);