0

原来我需要这样

我的黑醋栗标签是

我需要我的 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);`

4

1 回答 1

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);
于 2016-02-25T05:27:17.037 回答