简体   繁体   中英

Custom tab indicator view

I want to reproduce this tab indicator structure (screen is from nova launcher): a dropdown menu and an arrow in the right bottom corner.

在此处输入图片说明

I have no problem about code but i can't reproduce this appearance. I tried this:

mBar.addTab(mBar.newTab().setText(ctx.getString(R.string.tab_actions)).setTabListener(this).setCustomView(R.layout.navigation_spinner));

where mBar is sherlock support actionBar.

This is my layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
    android:layout_height="match_parent" android:layout_margin="-10dp"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical">
    <Button android:id="@+id/button1" android:layout_width="match_parent"
        android:layout_height="match_parent" android:text="Button" />

</LinearLayout>

and this is my result:

在此处输入图片说明

The problem is that the button in the central tab doesn't fill the tab indicator. How can i set a custom view that perfectly fill the indicator without margin or padding? Or i have to approach this in a different way to have the a result like the firs screen? Thanks in advice

What you are trying to do is really complicated, and will be hard to achieve.

If you want drop down menus you can try those :

menu/options.xml:

<item
    android:icon="@drawable/ic_menu_sort"
    android:showAsAction="ifRoom">
    <menu>
        <item
            android:id="@+id/menuSortNewest"
            android:title="Sort by newest" />
        <item
            android:id="@+id/menuSortRating"
            android:title="Sort by rating" />
    </menu>
</item>

Second option:

menu/options.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/menuSort"
        android:showAsAction="ifRoom"
        android:actionLayout="@layout/action_sort"  />
</menu>

layout/action_sort.xml:

<Spinner xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/ic_menu_refresh"
    android:entries="@array/order" />

Docs for menu resources - http://developer.android.com/guide/topics/resources/menu-resource.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM