Sau*_*ron 1 android android-spinner drop-down-menu
我需要在我的Android应用程序的顶部菜单栏中添加一个微调器,如下所示:

在Android 5.0之前,我只是使用:
final android.app.ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false); // DEPRACATED
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST)
Run Code Online (Sandbox Code Playgroud)
但该方法已被弃用.我已经浏览了所有示例:http://developer.android.com/samples/ui.html但是没有一个人有一个微调/下拉菜单来基于我的代码.
鉴于不推荐使用NAVIGATION_MODE_LIST,如何添加与Android 5.0兼容的微调器以及所有以前的版本?
更新:在我的代码中可以看到添加工具栏后,发生错误,因为它注意到即使它无法看到导入android.support.v7.widget.Toolbar; 清楚列出

您将需要将Spinner添加到工具栏:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:background="?attr/colorPrimary">
<Spinner
android:id="@+id/spinner_nav"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.v7.widget.Toolbar>
Run Code Online (Sandbox Code Playgroud)
然后,您需要禁用默认标题:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
// You can then retrieve and setup the Spinner as needed in your Activity/Fragment.
Run Code Online (Sandbox Code Playgroud)
从这个答案
Android Lollipop,从工具栏中的标题添加弹出菜单
| 归档时间: |
|
| 查看次数: |
9414 次 |
| 最近记录: |