简体   繁体   English

无法在操作栏中显示图标

[英]Can't display an icon in the actionbar

I'm trying to show a map icon downloaded from the official android developers source. 我正在尝试显示从官方Android开发人员源代码下载的地图图标。

I did everything as it should, but the icon won't show. 我做了应有的一切,但图标不会显示。 Here is my xml file named main_activity_bar : 这是我的名为main_activity_bar xml文件:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/mapIcon"
        android:icon="@drawable/ic_action_map"
        android:title="@string/mapIconTitle"
        android:showAsAction="always"
     />

</menu>

Here is the main activity xml: 这是xml的主要活动:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.gs.testApp.MainActivity"
    tools:ignore="MergeRootFrame" />

and this is what I have in the java class: 这就是我在java类中的内容:

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

Everything seems to be fine, but the icon wont show on the emulator. 一切似乎都很好,但图标不会在模拟器上显示。 Here is a screenshot: 这是一个截图:

在此输入图像描述

The minimum version is android 3.0 最低版本是android 3.0

Why the icon is not showing? 为什么图标没有显示? What Am I missing? 我错过了什么? I know that it is something really small, but I can't spot it. 我知道它确实很小,但我无法发现它。

Here is how I fixed it - in case that someone is facing the same issue. 以下是我修复它的方法 - 以防有人面临同样的问题。

I changed 我变了

android:showAsAction="always" to app:showAsAction="always" and I also placed the icon order android:orderInCategory="0" and the auto res xmlns:app="http://schemas.android.com/apk/res-auto" so now my xml looks like: android:showAsAction="always"app:showAsAction="always" ,我还放置了图标顺序android:orderInCategory="0"和auto res xmlns:app="http://schemas.android.com/apk/res-auto"所以现在我的xml看起来像:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:app="http://schemas.android.com/apk/res-auto">

    <item
        android:orderInCategory="0"
        android:id="@+id/mapIcon"
        android:icon="@drawable/ic_action_map"
        android:title="@string/mapIconTitle"
        app:showAsAction="always"
     />

</menu>

I dont think an icon is shown in the overflow menu. 我不认为溢出菜单中会显示一个图标。 Try changing your title to "t" or rotate the screen. 尝试将标题更改为“t”或旋转屏幕。 See if the icon appears this way. 看看图标是否以这种方式出现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM