如何显示溢出菜单项来操作栏的安卓 [英] How do I show Overflow Menu Items to Action Bar in Android
问题描述
我写一个Android应用程序中,我试图显示溢出菜单项来动作条的
I am writing an Android App in which i am trying to show Overflow Menu Items to ActionBar
使用这个伟大的教程链接:<一href="http://wptrafficanalyzer.in/blog/adding-action-items-and-overflow-menu-items-to-action-bar-in-android/">http://wptrafficanalyzer.in/blog/adding-action-items-and-overflow-menu-items-to-action-bar-in-android/
using this great tutorial link: http://wptrafficanalyzer.in/blog/adding-action-items-and-overflow-menu-items-to-action-bar-in-android/
问题:
Not getting Overflow Menu Items (Icon)
请参见下面的屏幕截图更加清晰:
Please see below Screen Shot for more clarity:
的Manifest.xml:
Manifest.xml:
<uses-sdk android:minSdkVersion="14" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:uiOptions="splitActionBarWhenNarrow"
>
items.xml:
items.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/phone"
android:title="@string/phone"
android:icon="@drawable/phone"
android:showAsAction="ifRoom|withText"
/>
<item
android:id="@+id/computer"
android:title="@string/computer"
android:icon="@drawable/computer"
android:showAsAction="ifRoom|withText"
/>
<item
android:id="@+id/gamepad"
android:title="@string/gamepad"
android:icon="@drawable/gamepad"
android:showAsAction="ifRoom|withText"
/>
<item
android:id="@+id/camera"
android:title="@string/camera"
android:icon="@drawable/camera"
android:showAsAction="ifRoom|withText"
/>
<item
android:id="@+id/video"
android:title="@string/video"
android:icon="@drawable/video"
android:showAsAction="ifRoom|withText"
/>
<item
android:id="@+id/email"
android:title="@string/email"
android:icon="@drawable/email"
android:showAsAction="ifRoom|withText"
/>
</menu>
我使用本教程,并尝试进行的图6:实施项目和溢出菜单中的拆分操作栏的
请帮我显示溢出菜单项(图标)动作条
现在,每当我做点击菜单按钮的模拟器,然后我得到休息菜单项的....
推荐答案
要显示了三个点图标,行动吧,只需使用下面的方法在你的OnCreate():
To show three dot icon, to Action Bar, just use below method in your OnCreate():
private void getOverflowMenu() {
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if(menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception e) {
e.printStackTrace();
}
}
这篇关于如何显示溢出菜单项来操作栏的安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!