[英]Overflow menu's 3 dots are not showing up in ActionBar
I am new to android and I am trying to create an overflow menu.我是 android 新手,我正在尝试创建一个溢出菜单。
The 3 dots on the ActionBar
are not showing (even after changing the app theme). ActionBar
上的 3 个点没有显示(即使在更改应用程序主题之后)。 After changing the app theme, it gets shown on the center of the screen "Android..CoordinatorLayout" how to get these 3 dots?更改应用程序主题后,它显示在屏幕中央“Android..CoordinatorLayout”如何获得这三个点?
My menu_main.xml
:我的
menu_main.xml
:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="100"
app:showAsAction="always" />
<item android:id="@+id/rtfm"
android:title="@string/action_settings"
android:orderInCategory="100"
app:showAsAction="never" />
</menu>
You should need something like this.你应该需要这样的东西。
A menu.xml
layout for the items under the res/menu
directory. res/menu
目录下项目的menu.xml
布局。
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_settings"
android:title="@string/action_settings"
app:showAsAction="never" />
...
</menu>
Then in your Activity
you must include this methods.然后在您的
Activity
您必须包含此方法。
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_settings:
// Do something
return true;
default:
return super.onOptionsItemSelected(item);
}
}
You can use this trick at Activity's onCreate:您可以在 Activity 的 onCreate 中使用此技巧:
if (savedInstanceState == null) {
//Show dots:
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if (menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception ex) {
// Ignore
}
} else {
//isResumed = true; ............. do something.....
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.