繁体   English   中英

自定义标签指示符视图

[英]Custom tab indicator view

我想重现此选项卡指示器结构(屏幕来自nova启动器):下拉菜单和右下角的箭头。

在此处输入图片说明

我对代码没有任何问题,但是我无法重现此外观。 我尝试了这个:

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

其中mBar是Sherlock支持actionBar。

这是我的布局:

<?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>

这是我的结果:

在此处输入图片说明

问题是中央选项卡中的按钮没有填充选项卡指示器。 如何设置自定义视图,以完全填充指标而没有边距或填充? 还是我必须以不同的方式来处理此问题,才能获得像“ firs”屏幕一样的结果? 谢谢建议

您试图做的事情确实很复杂,并且很难实现。

如果要下拉菜单,可以尝试以下方法:

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>

第二种选择:

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" />

菜单资源的文档-http: //developer.android.com/guide/topics/resources/menu-resource.html

暂无
暂无

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

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