我Implemeted一个飞旋如这里。现在我想将微调的动作条(设置微调的CustomView到动作条),但它不会出现在那里:(
I've implemeted spinner like here . And now I want to place spinner in ActionBar (setting spinner as CustomView to actionBar) but it doesn't appear there :(
Spinner spinner = (Spinner) findViewById(R.id.planets_spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.planets_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
actionBar.setCustomView(spinner);
这里是.XML
and here is .XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/parkfragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Spinner
android:id="@+id/planets_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
请,不建议使用动作条的下拉列表,因为我已经在使用动作条的标签,我不能使用它。机器人不允许同时使用它们二者。 任何帮助将AP preciated
Please, don't suggest to use ActionBar DropDown List, I can't use it because I'm already using ActionBar Tabs. android doesn't allow to use them both at the same time. Any help will be appreciated
推荐答案
您code缺少这一行:
Your code is missing this line:
actionBar.setDisplayShowCustomEnabled(true);
请参阅ActionBar#setDisplayShowCustomEnabled(boolean showCustom) ,以供参考。
See ActionBar#setDisplayShowCustomEnabled(boolean showCustom)
for reference.
为什么会出现一个空的的FrameLayout
在布局中占据所有的宽度和高度?去掉它。并删除的LinearLayout
,太。只要使用这个作为布局:
Why is there an empty FrameLayout
in your layout that occupies all the width and height? Remove it. And remove the LinearLayout
, too. Just use this as the layout:
<?xml version="1.0" encoding="utf-8"?>
<Spinner xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/planets_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
,然后写这样的事情,一切都正常:
And then write something like this and everything is fine:
actionBar.setCustomView(R.layout.your_layout_with_the_spinner);
actionBar.setDisplayShowCustomEnabled(true);
Spinner spinner = (Spinner) findViewById(R.id.planets_spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.planets_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
相关推荐
最新文章