2015-05-04 87 views
-1

我想将一个下拉菜单添加到Android操作栏中,就像在Google地图应用中一样。我不想包含任何第三方库,如actionbarsherlock,因为我相信我们可以使用android SDK来完成此操作。如何将下拉菜单添加到Android Action Bar

enter image description here

+0

可能重复http://stackoverflow.com/questions/11376101/drop-down-menu-添加一个工具栏on-action-bar) –

+0

为什么用上面链接列出的相同图像创建相同的问题? –

+0

你很有信心!为什么你还在尝试什么呢? – TheLittleNaruto

回答

1

您可以使用工具栏从程序兼容性库作为你的动作条,然后在工具栏中添加一个spinner因为工具栏就像一个普通的布局,你可以在其中添加视图。

这里是一个示例:

<android.support.v7.widget.Toolbar 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:minHeight="@dimen/triple_height_toolbar" 
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" > 

    <Spinner 
    android:id="@+id/planets_spinner" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" /> 

</android.support.v7.widget.Toolbar> 

,并找到在工具栏中的微调是调用工具栏内findViewById

toolbar = (Toolbar) findViewById(R.id.tool_bar); 
Spinnertitle = (Spinner)toolbar.findViewById(R.id.toolbar_title); 

Link Here是如何在你的应用程序

[操作栏上的下拉菜单(的
+0

将工具栏添加为“ActionBar”需要调用'setSupportActionBar()',您只需将工具栏实例作为参数传递。 – TheLittleNaruto