在动作条全角微调全角、动作

2023-09-12 02:00:48 作者:安生

我真的很喜欢我的应用程序有一个微调一直延伸我的动作条的整个长度,像在Gmail的4.0。任何人都知道如何实现这一目标?即使我在微调布局资源集match_parent,它不填满整个酒吧。 preferably,我希望能够把它填满整个酒吧除了我的行动项目,而不是使用分离动作条也是如此。

I'd really like my app to have a Spinner which stretches the entire length of my ActionBar, like the one in Gmail 4.0. Anyone know how to achieve this? Even if I set "match_parent" in the Spinner layout resource, it doesn't fill the entire bar. Preferably, I'd like to be able to have it fill the entire bar except for my action items, rather than using the split actionbar as well.

修改:请参见下面用一个实现我的答案内置的动作条,或使用自定义视图时hankystyles

EDIT: see my answer below for an implementation using the built-in actionbar, or hankystyles' when using a custom view

推荐答案

有点讨厌,我刚刚做了,但在这里是做什么用的方法,内置的微调操作栏中。所有你需要做的是让你的微调项目的主容器中的 RelativeLayout的并设置它的引力fillHorizo​​ntal,像这样:

Bit annoying that I've just done it, but here is a method of doing it using the built-in Spinner in the action bar. All you need to do is make your spinner item's main container a RelativeLayout and set its gravity to fillHorizontal, like so:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="fill_horizontal"
android:orientation="vertical" >

<TextView
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginBottom="-4dip"
    android:text="@string/gen_placeholder"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
    android:id="@+id/TextView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@android:id/text1"
    android:text="@string/app_name"
    android:textAppearance="?android:attr/textAppearanceSmall" />

</RelativeLayout>

和初始化适配器像这样:

And initialising the Adapter as so:

ArrayAdapter<CharSequence> barAdapter = new ArrayAdapter<CharSequence>(this, R.layout.subtitled_spinner_item, 
    android.R.id.text1, getResources().getStringArray(R.array.actionList));
barAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

,然后给所需的纺丝器跨越整个动作条(除了操作按钮):

which then gives the required spinner spanning the entire actionbar (except for the action buttons):