Android Lollipop,从工具栏中的标题添加弹出菜单 [英] Android Lollipop, add popup menu from title in toolbar
本文介绍了Android Lollipop,从工具栏中的标题添加弹出菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法看到从标题添加弹出菜单是如何完成的,就像许多材料设计示例中所示.任何帮助将不胜感激.
I'm unable to see how adding a popup menu from the title is accomplished like is shown in many of the material design examples. Any help would be much appreciated.
推荐答案
您将需要向工具栏添加一个微调器:
You're going to need to add a Spinner to the Toolbar:
<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>
然后您需要禁用默认标题:
You will then need to disable the default title:
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
然后,您可以根据需要在 Activity/Fragment 中检索和设置 Spinner.
You can then retrieve and setup the Spinner as needed in your Activity/Fragment.
这篇关于Android Lollipop,从工具栏中的标题添加弹出菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文