大佬教程收集整理的这篇文章主要介绍了如何在android 4.2中显示选项菜单,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
当我将清单中的主题设置为默认时,我能够看到菜单(菜单显示在顶部).如果我将清单中的主题设置为NotitleBar.我看不到菜单选项?
怎么解决?
以下是我在测试应用程序中使用的内容:
与清单:
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <application android:allowBACkup="true" android:icon="@drawable/ic_launcher" android:label="@String/app_name" android:theme="@android:style/Theme.NotitleBar" > <activity android:name="com.ssn.menuoptions.MainActivity" android:label="@String/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
和
@H_32_2@menu.xml文件<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://scheR_437_11845@as.android.com/apk/res/android"> <item android:id="@+id/menu_preferences" android@R_630_6964@="Preferences" /> </menu>
Java文件:
@Override public Boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main,menu); return true; }
有可能得到这样的东西:
谢谢!
setContentView(R.layout.activity_detail); // set option menu if has no hardware menu key Boolean hasMenu = ViewConfiguration.get(this).hasPeRMANentMenuKey(); if(!hasMenu){ //getWindow().setFlags(0x08000000,0x08000000); try { getWindow().addFlags(WindowManager.LayoutParams.class.getField("FLAG_NEEDS_MENU_KEY").geTint(null)); } catch (NoSuchFieldException E) { // Ignore since this field won't exist in most versions of Android } catch (illegalaccessexception E) { Log.w("Optionmenus","Could not access FLAG_NEEDS_MENU_KEY in addLegacyOverflowButton()",E); } }
以上是大佬教程为你收集整理的如何在android 4.2中显示选项菜单全部内容,希望文章能够帮你解决如何在android 4.2中显示选项菜单所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。