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

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

问题描述

我有麻烦与我的应用程序的动作条,问题是,仍呈现旧的Andr​​oid菜单。我已经检查等awnsers这个问题,但没有奏效。弥允许的最小的应用程序的SDK是7,但我在​​一个设备上运行了Android 4.2。

I'm having troubles with the ActionBar of my application, the problem is that is still showing the old android menu. I have checked other awnsers to this question but nothing has worked. Mi minimum app SDK allowed is 7 but I'm running in a device with Android 4.2.

我进口

import android.support.v7.app.ActionBarActivity;

这是我的onCreate()方法

This is my onCreate() method

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    inputTextView = (EditText) findViewById(R.id.inputText);
    outputTextView = (TextView) findViewById(R.id.outputText);
    inputTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            showMessage((View) textView);
            return true;
        }
    });
    registerForContextMenu(inputTextView);
}

这是我的onCreateOptionsMenu

This is my onCreateOptionsMenu

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.mainmenu, menu);
    return true;
}

这是我的XML

<item
    android:id="@+id/menu"
    android:orderInCategory="0"
    android:showAsAction="always"
    android:icon="@drawable/abc_ic_cab_done_holo_dark"
    >

</item>
<item
    android:id="@+id/lol"
    android:orderInCategory="0"
    android:showAsAction="ifRoom"
    android:icon="@drawable/abc_ic_go">
</item>

下面是我的appManifest.xml,我知道,它错过了包(我删除它,我试图将其添加)

Here is my appManifest.xml, I know that it miss the package (I removed it and I'm trying to add it)

<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:label="@string/app_name" android:name="com.ricardo.message.MainActivity" android:theme="@style/Theme.AppCompat.Light">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>

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

感谢您的帮助!

推荐答案

按照添加行动项目指南,你必须使用 http://schemas.android.com/apk/res-auto 模式的 showAsAction ,而不是安卓showAsAction

Per the Adding Action Items guide, you must use the http://schemas.android.com/apk/res-auto schema version of showAsAction, rather than android:showAsAction:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/menu"
        android:orderInCategory="0"
        app:showAsAction="always"
        android:icon="@drawable/abc_ic_cab_done_holo_dark" />
    <item
        android:id="@+id/lol"
        android:orderInCategory="0"
        app:showAsAction="ifRoom"
        android:icon="@drawable/abc_ic_go" />
</menu>

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

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