本文介绍了工具栏:溢出菜单按钮,处处流露出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:更新支持库,并使用工具栏后,溢出菜单按钮总是显示在使用和不使用硬件菜单按钮设备

Problem: after updating the support library and using Toolbars, the overflow menu button is always showing on devices with and without hardware menu button

我需要什么:我想要的溢出菜单按钮显示只有当设备没有硬件菜单按钮

What I Need: I want the overflow menu button to show only when the device has no hardware menu button

menu.xml文件

menu.xml

<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"
    app:showAsAction="never"
    android:title="@string/action_settings"/>

<item
    android:id="@+id/import_data"
    app:showAsAction="never"
    android:title="@string/import_data"/>

在活动(ActionBarActivity)

in the activity (ActionBarActivity)

@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;
}

和中的onCreate:setSupportActionBar(mToolbar);

and in onCreate : setSupportActionBar(mToolbar);

帮助将AP preciated!

Help would be appreciated!

推荐答案

我找到了解决我的问题:

I found the solution to my problem:

1 - 不叫 setSupportActionBar(mToolbar); 更多,而不是直接使用工具栏

1- don't call setSupportActionBar(mToolbar); any more, instead use Toolbar directly

2 - 检查设备是否有通过调用硬件菜单按钮<$c$c>ViewConfigurationCompat.hasPermanentMenuKey(ViewConfiguration.get(getApplicationContext()));

2- check if device has a hardware menu button by callingViewConfigurationCompat.hasPermanentMenuKey(ViewConfiguration.get(getApplicationContext())); :

3,如果设备有菜单按钮i onCreateOptionsMenu 返回true上,别的我膨胀的菜单中的工具栏

3- if device has menu button i return true on in onCreateOptionsMenu,else i inflate the menu in the Toolbar

这篇关于工具栏:溢出菜单按钮,处处流露出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-02 02:06