Ale*_*ran 29 android android-layout android-actionbar
我真的很喜欢我的应用程序有一个Spinner,它延伸我的ActionBar的整个长度,就像Gmail 4.0中的那个.谁知道如何实现这一目标?即使我在Spinner布局资源中设置"match_parent",它也不会填满整个栏.我希望能够让它填满整个栏,除了我的动作项,而不是使用分割动作栏.
编辑:请参阅下面的答案,了解使用内置操作栏的实现,或使用自定义视图时的hankystyles'

Ale*_*ran 28
有点烦人,我刚刚完成它,但这里有一个方法,使用操作栏中的内置Spinner.您需要做的就是使您的微调器项目的主容器a RelativeLayout并将其重力设置为fillHorizontal,如下所示:
<?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>
Run Code Online (Sandbox Code Playgroud)
并初始化适配器如下:
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);
Run Code Online (Sandbox Code Playgroud)
然后给出所需的微调器跨越整个操作栏(动作按钮除外):

小智 20
我的gmail应用程序上的微调器也跨越了我的操作栏的整个宽度.这个解决方案对我有用:
View spinner = getLayoutInflater().inflate(R.layout.actionbar_spinner, null);
actionBar.setCustomView(spinner);
actionBar.setDisplayShowCustomEnabled(true);
Run Code Online (Sandbox Code Playgroud)
微调器布局如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="fill_horizontal" >
<Spinner
android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/spinner_text"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我怀疑有一个更好的解决方案,通过覆盖默认的动作栏导航风格可以有这样的,但我无法立即得到了该工作.
| 归档时间: |
|
| 查看次数: |
15616 次 |
| 最近记录: |