支持设计窗口小部件TabLayout中的自定义选项卡指示器形状

时间:2015-08-29 14:40:28

标签: android android-support-library android-design-library androiddesignsupport

实际上默认情况下,标签是矩形,但我想制作自定义形状。我已经完成了一些编码,但现在选项卡之间有一些空间,我希望所有这些都在一起。请帮忙!

What I Have Done

但是what I am trying to do是:

MainActivity.java

    final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.addTab(tabLayout.newTab().setText("First"));
    tabLayout.addTab(tabLayout.newTab().setText("Second"));
    tabLayout.addTab(tabLayout.newTab().setText("Third"));
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

activity_main.xml中

    <android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="27dp"
    android:minHeight="?attr/actionBarSize"
    app:tabBackground="@drawable/customtabhandler"
    />

customtabhandler.xml

<?xml version="1.0" encoding="utf-8"?>

<!-- Non focused states -->
<item android:state_selected="false"
    android:drawable="@drawable/defualttab" />

<!-- Focused states (such as when focused with a d-pad or mouse hover) -->
<item  android:state_selected="true"
    android:drawable="@drawable/onselectedtab" />

defualttab.xml

<!-- Colored rectangle-->
<item>
    <shape android:shape="rectangle">
        <size
            android:width="95dp"
            android:height="20dp" />
        <solid android:color="#ff30a3b6" />
    </shape>
</item>

onselectedtab.xml

<!-- Colored rectangle-->
<item>
    <shape android:shape="rectangle">
        <size
            android:width="95dp"
            android:height="20dp" />
        <solid android:color="#89aaaaaa" />
    </shape>
</item>

<!-- This rectangle for the left side -->
<!-- Its color should be the same as layout's background -->
<item
    android:right="100dp"
    android:left="-100dp"
    android:top="-100dp"
    android:bottom="-100dp">
    <rotate
        android:fromDegrees="45">
        <shape android:shape="rectangle">
            <solid android:color="#ff30a3b6" />
        </shape>
    </rotate>
</item>

<!-- This rectangle for the right side -->
<!-- Their color should be the same as layout's background -->
<item
    android:right="-100dp"
    android:left="100dp"
    android:top="-100dp"
    android:bottom="-100dp">
    <rotate
        android:fromDegrees="45">
        <shape android:shape="rectangle">
            <solid android:color="#ff30a3b6" />
        </shape>
    </rotate>
</item>

任何帮助都将受到高度赞赏..

P.S。我在stackoverflow上搜索了很多,我找到的只是旧库,但不是新库..

0 个答案:

没有答案