动作条上不显示在Android的图标 [英] ActionBar is not displaying icons in android

查看:119
本文介绍了动作条上不显示在Android的图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力,以显示在动作条的图标,但我不能弥补请指导我,指出我在哪里,我错了。这是我的code

I have been trying to display icons in the Actionbar but i could not make it up please guide me and point me out where I am going wrong. Here is my code

acivity_main_actions.xml

acivity_main_actions.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">
<!-- Search / will display always -->
<item android:id="@+id/action_search"
      android:icon="@drawable/ic_action_search"
      android:title="@string/action_search"
      android:showAsAction="always"/>

<!-- Location Found -->
<item android:id="@+id/action_location_found"
      android:icon="@drawable/ic_action_location_found"
      android:title="@string/action_location_found"
      android:showAsAction="ifRoom" />

<!-- Refresh -->
<item android:id="@+id/action_refresh"
      android:icon="@drawable/ic_action_refresh"
      android:title="@string/action_refresh"
      android:showAsAction="ifRoom" />

<!-- Help -->
<item android:id="@+id/action_help"
      android:icon="@drawable/ic_action_help"
      android:title="@string/action_help"
      android:showAsAction="never"/>

<!-- Check updates -->
<item android:id="@+id/action_check_updates"
      android:icon="@drawable/ic_action_refresh"
      android:title="@string/action_check_updates"
      android:showAsAction="never" />
</menu>    

MainActivity.java

MainActivity.java

public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
     MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.layout.activity_main_actions, menu);

        return super.onCreateOptionsMenu(menu);

}

AndroidManifest.xml中

AndroidManifest.xml

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="19" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.ThrashingBlue.example.entertain.MainActivity"
        android:label="@string/app_name" 
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

以上数字表明,我得到的结果。但我想在动作条的搜索图标。

The above figure show the result that I got. But I want the search icon on the actionbar.

推荐答案

使用 应用程序:showAsAction =总是 insted的的android:showAsAction =总是

Use app:showAsAction="always" insted of android:showAsAction="always"

这篇关于动作条上不显示在Android的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆