问题描述
我试图表现出从官方Android开发源下载一个地图图标。
I'm trying to show a map icon downloaded from the official android developers source.
我做的一切都是理所应当,但图标将不会显示。这里是我命名的XML文件 main_activity_bar
:
I did everything as it should, but the icon won't show.Here is my xml file named main_activity_bar
:
<?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>
下面是主要活动的xml:
Here is the main activity 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" />
这是我在java类:
and this is what I have in the java class:
@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:
最低版本为安卓3.0
The minimum version is 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.
我改变了
安卓showAsAction =总是
到应用程序:showAsAction =总是
,我也放在图标为了安卓orderInCategory =0
和自动资源的xmlns:程序=http://schemas.android.com/apk/res-自动
所以现在我的XML如下:
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:
<?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>
这篇关于无法显示在动作条图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!