I want to include a drop down menu to android action bar like in the Google Maps app. I don not want to include any third party libraries such as actionbarsherlock since I believe we can do this using android SDK.
我想在谷歌地图应用程序中包含一个下拉菜单到Android操作栏。我不想包括任何第三方库,例如actionbarsherlock,因为我相信我们可以使用android SDK来做到这一点。
1 个解决方案
#1
You can use a toolbar from the AppCompat library to act as your actionbar and then add a spinner
within the toolbar because toolbar acts like a regular layout where you can add views within it.
您可以使用AppCompat库中的工具栏作为操作栏,然后在工具栏中添加微调器,因为工具栏的作用类似于常规布局,您可以在其中添加视图。
here is a sample:
这是一个示例:
<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>
And finding the spinner within the toolbar is calling the findViewById
within the toolbar.
在工具栏中查找微调器是在工具栏中调用findViewById。
toolbar = (Toolbar) findViewById(R.id.tool_bar);
Spinnertitle = (Spinner)toolbar.findViewById(R.id.toolbar_title);
Link Here is how to add a toolbar in your application
链接以下是如何在应用程序中添加工具栏
#1
You can use a toolbar from the AppCompat library to act as your actionbar and then add a spinner
within the toolbar because toolbar acts like a regular layout where you can add views within it.
您可以使用AppCompat库中的工具栏作为操作栏,然后在工具栏中添加微调器,因为工具栏的作用类似于常规布局,您可以在其中添加视图。
here is a sample:
这是一个示例:
<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>
And finding the spinner within the toolbar is calling the findViewById
within the toolbar.
在工具栏中查找微调器是在工具栏中调用findViewById。
toolbar = (Toolbar) findViewById(R.id.tool_bar);
Spinnertitle = (Spinner)toolbar.findViewById(R.id.toolbar_title);
Link Here is how to add a toolbar in your application
链接以下是如何在应用程序中添加工具栏