菜单项未显示在操作栏上

时间:2023-01-16 14:14:10

I have made a completely new project. I have added items to the menu layout file. Those items do not show up on the action bar's right side. I remember that an icon with three dots shows up which opens up the menu.

我做了一个全新的项目。我已将项目添加到菜单布局文件中。这些项目不会显示在操作栏的右侧。我记得有一个带有三个点的图标会打开菜单。

菜单项未显示在操作栏上

Here is my Activity

这是我的活动

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ActionBar actionBar = getActionBar();
        actionBar.setBackgroundDrawable(new ColorDrawable(Color.BLUE));     
        actionBar.show();
    }

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

}

And here is my main.xml

这是我的main.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="@string/action_option1"/>
    <item
        android:id="@+id/action_settings34"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="@string/action_option2"/>
    <item
        android:id="@+id/action_settings3"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="@string/action_option3"/>


</menu>

10 个解决方案

#1


42  

Since you set the showAsAction attribute to never, then these menu items will never show as action views. Try this:

由于您将showAsAction属性设置为never,因此这些菜单项永远不会显示为操作视图。尝试这个:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:showAsAction="ifRoom|withText"
        android:title="@string/action_option1"/>
    <item
        android:id="@+id/action_settings34"
        android:orderInCategory="100"
        android:showAsAction="ifRoom|withText"
        android:title="@string/action_option2"/>
    <item
        android:id="@+id/action_settings3"
        android:orderInCategory="100"
        android:showAsAction="ifRoom|withText"
        android:title="@string/action_option3"/>

</menu>

#2


116  

Context

There seems to be a misunderstanding about this showAsAction property in the menu configuration. The information I find in the many * answers always seem to be incomplete. So here is an attempt to change that.

在菜单配置中似乎存在对此showAsAction属性的误解。我在许多*答案中找到的信息似乎总是不完整的。所以这是尝试改变它。

Three dot | overflow | options menu

There is no way to control if your actionbar will show the three dot overflow menu or not in code.

无法控制操作栏是否在代码中显示三点溢出菜单。

Well you can force it not to show by having no options menu for sure. And to be fair you can hack around this, more info at How to force use of overflow menu on devices with menu button

那么你可以通过没有选项菜单来强制它不显示。公平地说,你可以解决这个问题,如何使用菜单按钮强制使用溢出菜单

The dots showing or not depends on the device you're testing on. Devices with a menu button will NOT SHOW the three dot icon on the actionbar since users can use the menu button on the device.

显示与否的点取决于您正在测试的设备。具有菜单按钮的设备将不会显示操作栏上的三个点图标,因为用户可以使用设备上的菜单按钮。

菜单项未显示在操作栏上

Devices that don't have this options menu button (like the nexus devices starting from Galaxy) have no alternative to trigger that options menu. Running the same app on these devices will show the three dot overflow menu option in the actionbar.

没有此选项菜单按钮的设备(如从Galaxy开始的nexus设备)无法触发该选项菜单。在这些设备上运行相同的应用程序将在操作栏中显示三点溢出菜单选项。

菜单项未显示在操作栏上

What you can control

There is the showAsAction option in the menu xml file that you can use to control how that single menu option will show up in the actionbar.

菜单xml文件中有showAsAction选项,您可以使用该选项控制单个菜单选项在操作栏中的显示方式。

According to official menu resource doc the options are:

根据官方菜单资源文档,选项是:

android:showAsAction=["ifRoom" | "never" | "withText" | "always" | "collapseActionView"]

The ifRoom flag only shows the option if there is enough room. This should be your first choice in most cases. This will however condense the title in the actionbar (see vertical oriented screenshot).

如果有足够的空间,ifRoom标志仅显示该选项。在大多数情况下,这应该是您的首选。然而,这将缩小操作栏中的标题(请参阅垂直方向的屏幕截图)。

The never flag will have this option always in the overflow menu and never directly in the actionbar.

never标志将始终在溢出菜单中具有此选项,并且永远不会直接在操作栏中。

The use of the always flag is discouraged since it will force the option to always appear in the acitonbar. Even if running on a very small screen size. This could render the title completely invisible.

不鼓励使用always标志,因为它会强制选项始终出现在acitonbar中。即使在非常小的屏幕尺寸上运行。这可能会使标题完全不可见。

As you might now an option menu can have both an android:title and an android:icon property. You can use the withText flag together with always or ifRoom (use a pipe | in between) to force the text of the item to show next to the icon when rendered in the actionbar.

正如您现在可能的选项菜单可以同时具有android:title和android:icon属性。您可以将withText标志与always或ifRoom(在其间使用管道)一起使用,以强制在操作栏中呈现时项目的文本显示在图标旁边。

The collapseActionView is only supported from API level 14 so let me ignore that.

collapseActionView仅支持API级别14,所以让我忽略它。

A screenshot showing the below code snippet in action on a device hold in portrait mode:

屏幕截图显示了以纵向模式保留的设备上的以下代码段:

菜单项未显示在操作栏上

And another screenshot where there is more space in the actionbar thanks to the landscape mode:

另一个屏幕截图,由于横向模式,操作栏中有更多空间:

菜单项未显示在操作栏上

Android Documentation

The best development doc about this actionbar would be the actionbar guide. If you're looking more for design guidelines follow this link. The menu resource link was listed before. For menus in general check this.

关于此操作栏的最佳开发文档将是操作栏指南。如果您正在寻找更多设计指南,请点击此链接。之前列出了菜单资源链接。对于菜单一般检查这个。

Code snippet

The code only for reference since that part seems to be right in most answers. A more complete example can be found at https://github.com/AndroidExamples/fragment-navigation

该代码仅供参考,因为该部分似乎在大多数答案中都是正确的。可以在https://github.com/AndroidExamples/fragment-navigation找到更完整的示例

The /res/menu/main.xml file contents:

/res/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="be.hcpl.android.example.MainActivity" >

<!-- an option that never appears as a fixed text/icon in the actionbar -->
<item android:id="@+id/action_one"
    android:title="@string/action_one"
    android:orderInCategory="100"
    app:showAsAction="never" />

<!-- another option that only appears if there is enough room -->
<item android:id="@+id/action_two"
    android:title="@string/action_two"
    android:orderInCategory="200"
    app:showAsAction="ifRoom" />

<!-- a last option that always appears -->
<item android:id="@+id/action_three"
    android:title="@string/action_three"
    android:orderInCategory="300"
    app:showAsAction="always" />

<!-- an option to show with both icon and text -->
<item android:id="@+id/action_four"
    android:icon="@android:drawable/ic_menu_directions"
    android:title="@string/action_four"
    android:orderInCategory="400"
    app:showAsAction="withText|always" />

<!-- an option to always show as an icon only -->
<item android:id="@+id/action_five"
    android:icon="@android:drawable/ic_menu_info_details"
    android:title="@string/action_five"
    android:orderInCategory="500"
    app:showAsAction="always" />

</menu>

Some linked answers

#3


9  

I think you want to show the overflow menu icon on the top right always and want your menu to open from there. Try something like following to force it there:

我想你总是要在右上角显示溢出菜单图标,并希望你的菜单从那里打开。尝试类似下面的内容强制它:

Inside your onCreate() do:

在你的onCreate()里面做:

  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
    }

It will force the App to show the overflow menu. The menu button will still work, but it will open the menu in the top right corner. Taken from this answer at How to force use of overflow menu on devices with menu button . This might be a kind of 'hack' but it works.

它将强制App显示溢出菜单。菜单按钮仍然有效,但它会打开右上角的菜单。摘自如何使用菜单按钮在设备上强制使用溢出菜单。这可能是一种“黑客”,但它有效。

Edit:

编辑:

Based on useful comments from @gunar, I request not to use this method. Following are the reasons:

基于@gunar的有用评论,我请求不使用此方法。以下是原因:

  • The private field sHasPermanentMenuKeycan be refactored in a future releases. Your app will stop working then.

    私有字段sHasPermanentMenuKeycan将在未来的版本中进行重构。您的应用将停止工作。

  • Also If you force moving action items to action bar because you're used to them, you'll end up confusing users that are used to how apps run on their device. Those with hardware menu key will be used to have the options showed from menu hardware key. If you intentionally show them the three dots of overflow menu, it might confuse them.

    此外,如果您强制将操作项移动到操作栏,因为您已经习惯了它们,那么您最终会混淆习惯于在其设备上运行应用程序的用户。具有硬件菜单键的那些将用于从菜单硬件键显示选项。如果你故意向他们展示溢出菜单的三个点,它可能会混淆它们。

So let all the apps be uniform in that sense. Those devices with no hardware key for menu items will show those automatically.

因此,让所有应用程序在这个意义上都是统一的。那些没有菜单项硬件键的设备会自动显示这些设备。

#4


6  

OR you could create a structure like:

或者您可以创建一个结构,如:

<?xml version="1.0" encoding="utf-8"?>
<menu >
<item
    android:id="@+id/menu_main"
    android:icon="@drawable/icon_menu"
    android:showAsAction="always"
    android:title="@string/menu_A"
    android:visible="true">
    <menu>
        <item
            android:id="@+id/menu_settings1"
            android:showAsAction="never"
            android:title="@string/menu_A1"/>
        <item
            android:id="@+id/menu_settings2"
            android:showAsAction="never"
            android:title="@string/menu_A2"/>
        <item
            android:id="@+id/menu_settings3"
            android:showAsAction="never"
            android:title="@string/menu_A3"/>
    </menu>
</item>
</menu>

Where the icon_menu you can create a new icon set with the three points icon clipart.

在icon_menu中,您可以使用三点图标剪贴画创建一个新图标集。

#5


4  

I had the same problem. And I did all of the things that were said above. My problem was I forgot to override onCreateoptionMenu(Menu menu).

我有同样的问题。我做了上面提到的所有事情。我的问题是我忘了覆盖onCreateoptionMenu(菜单菜单)。

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu,menu);
    return super.onCreateOptionsMenu(menu);
}

#6


3  

Add

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

in the onCreate method.

在onCreate方法中。

#7


2  

After searching and reading a lot of answer, I found that there is another little thing that you should pay attention to.

在搜索并阅读了大量答案之后,我发现还有一件事你应该注意。

At least it was my problem and I didn't find an answer of any above. On your .XML file. Your android:showAsAction= shouldn't be form android package, it should be from app package like in the example below:

至少这是我的问题,我没有找到任何上述答案。在.XML文件上。你的android:showAsAction =不应该是android包的形式,它应该来自app包,如下例所示:

app:showAsAction=

Don't forget to import the app package.

不要忘记导入应用程序包。

#8


0  

all answers above explained this issue well

上面的所有答案都解释了这个问题

but can we override this limitation and have the overflow menu item?!!

但是我们可以覆盖这个限制并拥有溢出菜单项吗?!!

yes we can hack

是的,我们可以破解

 private void makeActionOverflowMenuShown() {
    //devices with hardware menu button (e.g. Samsung Note) don't show action overflow menu
    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) {
        Log.d(TAG, e.getLocalizedMessage());
    }
}

and inside onCreate call it

并在onCreate里面调用它

references: https://*.com/a/13098824/4251431

参考:https://*.com/a/13098824/4251431

#9


0  

You need to call this function in onCreate function of the activity.

您需要在活动的onCreate函数中调用此函数。

RequestWindowFeature (Window.FEATURE_ACTION_BAR);

#10


0  

add custom namespace like this to showAsAction and actionViewClass

像showAsAction和actionViewClass一样添加这样的自定义命名空间

<menu xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/search"
    android:title="@string/search"
    android:icon="@drawable/ic_search"
    app:showAsAction="collapseActionView|ifRoom"
    app:actionViewClass="android.widget.SearchView" />

#1


42  

Since you set the showAsAction attribute to never, then these menu items will never show as action views. Try this:

由于您将showAsAction属性设置为never,因此这些菜单项永远不会显示为操作视图。尝试这个:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:showAsAction="ifRoom|withText"
        android:title="@string/action_option1"/>
    <item
        android:id="@+id/action_settings34"
        android:orderInCategory="100"
        android:showAsAction="ifRoom|withText"
        android:title="@string/action_option2"/>
    <item
        android:id="@+id/action_settings3"
        android:orderInCategory="100"
        android:showAsAction="ifRoom|withText"
        android:title="@string/action_option3"/>

</menu>

#2


116  

Context

There seems to be a misunderstanding about this showAsAction property in the menu configuration. The information I find in the many * answers always seem to be incomplete. So here is an attempt to change that.

在菜单配置中似乎存在对此showAsAction属性的误解。我在许多*答案中找到的信息似乎总是不完整的。所以这是尝试改变它。

Three dot | overflow | options menu

There is no way to control if your actionbar will show the three dot overflow menu or not in code.

无法控制操作栏是否在代码中显示三点溢出菜单。

Well you can force it not to show by having no options menu for sure. And to be fair you can hack around this, more info at How to force use of overflow menu on devices with menu button

那么你可以通过没有选项菜单来强制它不显示。公平地说,你可以解决这个问题,如何使用菜单按钮强制使用溢出菜单

The dots showing or not depends on the device you're testing on. Devices with a menu button will NOT SHOW the three dot icon on the actionbar since users can use the menu button on the device.

显示与否的点取决于您正在测试的设备。具有菜单按钮的设备将不会显示操作栏上的三个点图标,因为用户可以使用设备上的菜单按钮。

菜单项未显示在操作栏上

Devices that don't have this options menu button (like the nexus devices starting from Galaxy) have no alternative to trigger that options menu. Running the same app on these devices will show the three dot overflow menu option in the actionbar.

没有此选项菜单按钮的设备(如从Galaxy开始的nexus设备)无法触发该选项菜单。在这些设备上运行相同的应用程序将在操作栏中显示三点溢出菜单选项。

菜单项未显示在操作栏上

What you can control

There is the showAsAction option in the menu xml file that you can use to control how that single menu option will show up in the actionbar.

菜单xml文件中有showAsAction选项,您可以使用该选项控制单个菜单选项在操作栏中的显示方式。

According to official menu resource doc the options are:

根据官方菜单资源文档,选项是:

android:showAsAction=["ifRoom" | "never" | "withText" | "always" | "collapseActionView"]

The ifRoom flag only shows the option if there is enough room. This should be your first choice in most cases. This will however condense the title in the actionbar (see vertical oriented screenshot).

如果有足够的空间,ifRoom标志仅显示该选项。在大多数情况下,这应该是您的首选。然而,这将缩小操作栏中的标题(请参阅垂直方向的屏幕截图)。

The never flag will have this option always in the overflow menu and never directly in the actionbar.

never标志将始终在溢出菜单中具有此选项,并且永远不会直接在操作栏中。

The use of the always flag is discouraged since it will force the option to always appear in the acitonbar. Even if running on a very small screen size. This could render the title completely invisible.

不鼓励使用always标志,因为它会强制选项始终出现在acitonbar中。即使在非常小的屏幕尺寸上运行。这可能会使标题完全不可见。

As you might now an option menu can have both an android:title and an android:icon property. You can use the withText flag together with always or ifRoom (use a pipe | in between) to force the text of the item to show next to the icon when rendered in the actionbar.

正如您现在可能的选项菜单可以同时具有android:title和android:icon属性。您可以将withText标志与always或ifRoom(在其间使用管道)一起使用,以强制在操作栏中呈现时项目的文本显示在图标旁边。

The collapseActionView is only supported from API level 14 so let me ignore that.

collapseActionView仅支持API级别14,所以让我忽略它。

A screenshot showing the below code snippet in action on a device hold in portrait mode:

屏幕截图显示了以纵向模式保留的设备上的以下代码段:

菜单项未显示在操作栏上

And another screenshot where there is more space in the actionbar thanks to the landscape mode:

另一个屏幕截图,由于横向模式,操作栏中有更多空间:

菜单项未显示在操作栏上

Android Documentation

The best development doc about this actionbar would be the actionbar guide. If you're looking more for design guidelines follow this link. The menu resource link was listed before. For menus in general check this.

关于此操作栏的最佳开发文档将是操作栏指南。如果您正在寻找更多设计指南,请点击此链接。之前列出了菜单资源链接。对于菜单一般检查这个。

Code snippet

The code only for reference since that part seems to be right in most answers. A more complete example can be found at https://github.com/AndroidExamples/fragment-navigation

该代码仅供参考,因为该部分似乎在大多数答案中都是正确的。可以在https://github.com/AndroidExamples/fragment-navigation找到更完整的示例

The /res/menu/main.xml file contents:

/res/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="be.hcpl.android.example.MainActivity" >

<!-- an option that never appears as a fixed text/icon in the actionbar -->
<item android:id="@+id/action_one"
    android:title="@string/action_one"
    android:orderInCategory="100"
    app:showAsAction="never" />

<!-- another option that only appears if there is enough room -->
<item android:id="@+id/action_two"
    android:title="@string/action_two"
    android:orderInCategory="200"
    app:showAsAction="ifRoom" />

<!-- a last option that always appears -->
<item android:id="@+id/action_three"
    android:title="@string/action_three"
    android:orderInCategory="300"
    app:showAsAction="always" />

<!-- an option to show with both icon and text -->
<item android:id="@+id/action_four"
    android:icon="@android:drawable/ic_menu_directions"
    android:title="@string/action_four"
    android:orderInCategory="400"
    app:showAsAction="withText|always" />

<!-- an option to always show as an icon only -->
<item android:id="@+id/action_five"
    android:icon="@android:drawable/ic_menu_info_details"
    android:title="@string/action_five"
    android:orderInCategory="500"
    app:showAsAction="always" />

</menu>

Some linked answers

#3


9  

I think you want to show the overflow menu icon on the top right always and want your menu to open from there. Try something like following to force it there:

我想你总是要在右上角显示溢出菜单图标,并希望你的菜单从那里打开。尝试类似下面的内容强制它:

Inside your onCreate() do:

在你的onCreate()里面做:

  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
    }

It will force the App to show the overflow menu. The menu button will still work, but it will open the menu in the top right corner. Taken from this answer at How to force use of overflow menu on devices with menu button . This might be a kind of 'hack' but it works.

它将强制App显示溢出菜单。菜单按钮仍然有效,但它会打开右上角的菜单。摘自如何使用菜单按钮在设备上强制使用溢出菜单。这可能是一种“黑客”,但它有效。

Edit:

编辑:

Based on useful comments from @gunar, I request not to use this method. Following are the reasons:

基于@gunar的有用评论,我请求不使用此方法。以下是原因:

  • The private field sHasPermanentMenuKeycan be refactored in a future releases. Your app will stop working then.

    私有字段sHasPermanentMenuKeycan将在未来的版本中进行重构。您的应用将停止工作。

  • Also If you force moving action items to action bar because you're used to them, you'll end up confusing users that are used to how apps run on their device. Those with hardware menu key will be used to have the options showed from menu hardware key. If you intentionally show them the three dots of overflow menu, it might confuse them.

    此外,如果您强制将操作项移动到操作栏,因为您已经习惯了它们,那么您最终会混淆习惯于在其设备上运行应用程序的用户。具有硬件菜单键的那些将用于从菜单硬件键显示选项。如果你故意向他们展示溢出菜单的三个点,它可能会混淆它们。

So let all the apps be uniform in that sense. Those devices with no hardware key for menu items will show those automatically.

因此,让所有应用程序在这个意义上都是统一的。那些没有菜单项硬件键的设备会自动显示这些设备。

#4


6  

OR you could create a structure like:

或者您可以创建一个结构,如:

<?xml version="1.0" encoding="utf-8"?>
<menu >
<item
    android:id="@+id/menu_main"
    android:icon="@drawable/icon_menu"
    android:showAsAction="always"
    android:title="@string/menu_A"
    android:visible="true">
    <menu>
        <item
            android:id="@+id/menu_settings1"
            android:showAsAction="never"
            android:title="@string/menu_A1"/>
        <item
            android:id="@+id/menu_settings2"
            android:showAsAction="never"
            android:title="@string/menu_A2"/>
        <item
            android:id="@+id/menu_settings3"
            android:showAsAction="never"
            android:title="@string/menu_A3"/>
    </menu>
</item>
</menu>

Where the icon_menu you can create a new icon set with the three points icon clipart.

在icon_menu中,您可以使用三点图标剪贴画创建一个新图标集。

#5


4  

I had the same problem. And I did all of the things that were said above. My problem was I forgot to override onCreateoptionMenu(Menu menu).

我有同样的问题。我做了上面提到的所有事情。我的问题是我忘了覆盖onCreateoptionMenu(菜单菜单)。

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu,menu);
    return super.onCreateOptionsMenu(menu);
}

#6


3  

Add

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

in the onCreate method.

在onCreate方法中。

#7


2  

After searching and reading a lot of answer, I found that there is another little thing that you should pay attention to.

在搜索并阅读了大量答案之后,我发现还有一件事你应该注意。

At least it was my problem and I didn't find an answer of any above. On your .XML file. Your android:showAsAction= shouldn't be form android package, it should be from app package like in the example below:

至少这是我的问题,我没有找到任何上述答案。在.XML文件上。你的android:showAsAction =不应该是android包的形式,它应该来自app包,如下例所示:

app:showAsAction=

Don't forget to import the app package.

不要忘记导入应用程序包。

#8


0  

all answers above explained this issue well

上面的所有答案都解释了这个问题

but can we override this limitation and have the overflow menu item?!!

但是我们可以覆盖这个限制并拥有溢出菜单项吗?!!

yes we can hack

是的,我们可以破解

 private void makeActionOverflowMenuShown() {
    //devices with hardware menu button (e.g. Samsung Note) don't show action overflow menu
    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) {
        Log.d(TAG, e.getLocalizedMessage());
    }
}

and inside onCreate call it

并在onCreate里面调用它

references: https://*.com/a/13098824/4251431

参考:https://*.com/a/13098824/4251431

#9


0  

You need to call this function in onCreate function of the activity.

您需要在活动的onCreate函数中调用此函数。

RequestWindowFeature (Window.FEATURE_ACTION_BAR);

#10


0  

add custom namespace like this to showAsAction and actionViewClass

像showAsAction和actionViewClass一样添加这样的自定义命名空间

<menu xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/search"
    android:title="@string/search"
    android:icon="@drawable/ic_search"
    app:showAsAction="collapseActionView|ifRoom"
    app:actionViewClass="android.widget.SearchView" />