简体   繁体   English

自定义标签指示符视图

[英]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. 我想重现此选项卡指示器结构(屏幕来自nova启动器):下拉菜单和右下角的箭头。

在此处输入图片说明

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. 其中mBar是Sherlock支持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? 还是我必须以不同的方式来处理此问题,才能获得像“ firs”屏幕一样的结果? 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: 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 / 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: 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 菜单资源的文档-http: //developer.android.com/guide/topics/resources/menu-resource.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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