我有一个使用手机菜单按钮的项目。但有些手机没有选项来获取菜单[例如:Moto G],而是使用动作栏,但Android 2.1不支持。我希望菜单适用于Android 2.1以及4.4我该怎么做?
答案 0 :(得分:1)
这是您需要阅读的文章:Say Goodbye to the Menu Button
如果您的应用在没有专用菜单按钮的设备上运行,则 system决定是否将操作溢出添加到导航 bar,根据您声明支持的API级别 清单元素。逻辑归结为:
如果将minSdkVersion或targetSdkVersion设置为11或更高, 系统不会添加传统溢出按钮。
否则,系统将在运行时添加旧版溢出按钮 在Android 3.0或更高版本上。
唯一的例外是,如果将minSdkVersion设置为10或更低, 将targetSdkVersion设置为11,12或13,并且不使用ActionBar, 系统将在运行您的应用程序时添加旧版溢出按钮 在Android 4.0或更高版本的手机上。
答案 1 :(得分:1)
实现这一目标的两种方法:
创建一个按钮(比如菜单)并将其添加到操作栏。实现您自己的方法(例如:Spinner),在单击按钮作为菜单时,将选项显示为下拉列表。
另一种方法是创建上下文菜单
答案 2 :(得分:0)
您可以创建自定义按钮,并在点击时调用openOptionsMenu();
。
编辑:
禁用操作栏上的默认设置按钮并添加此按钮
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/settings_button"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:padding="10dp"
android:orientation="vertical">
<View
android:layout_width="5dp"
android:layout_height="5dp"
android:background="@color/black"
android:layout_margin="2dp"/>
<View
android:layout_width="5dp"
android:layout_height="5dp"
android:background="@color/black"
android:layout_margin="2dp"/>
<View
android:layout_width="5dp"
android:layout_height="5dp"
android:background="@color/black"
android:layout_margin="2dp"/>
</LinearLayout>
答案 3 :(得分:0)