0

I cannot get icons to show in the action bar.

I am using the most recent SDK with eclipse.

I am trying to do this tutorial http://developer.android.com/training/basics/actionbar/adding-buttons.html

My MainActivity.java is

package com.example.myfirstapp;

import android.os.Bundle;
import android.app.Activity;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuInflater;

public class MainActivity extends ActionBarActivity   {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

  @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu items for use in the action bar
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main, menu);
        return super.onCreateOptionsMenu(menu);
    }    
}

My main.xml under menu is

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:id="@+id/action_search"
          android:icon="@drawable/ic_action_search"
          android:title="@string/action_search"
          android:showAsAction="always" />
    <item android:id="@+id/action_settings"
          android:title="@string/action_settings"
          android:showAsAction="always" >
    </item>

</menu>

But I dont see the menu items. It looks like this menu missing items Any help on how to get these menu items shows would be useful.

Thank you.

4

6 に答える 6

1

置くだけ

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

変更する

app:showAsAction="always" 

android:showAsAction="always"
于 2014-11-04T15:58:39.283 に答える
1

すでにこれを行っているに違いないと確信していますが、アイコンをダウンロードして res > drawable フォルダーに配置しましたか? 暗いアクション バーを使用している場合は、必ず明るい色のアイコンをインストールしてください。逆の場合も同様です。私は同じチュートリアルに従いましたが、うまくいきました。あなたのコードは正しいようです。

于 2013-09-16T03:00:48.273 に答える
0

あなたの問題はここにあると思います:

return super.onCreateOptionsMenu(menu);

これを次のように変更します。

return Boolean.TRUE;

出典:Androidのメニューと私の古いプロジェクト。

于 2013-08-10T17:43:14.343 に答える
0

チュートリアルを段階的に実行した後、この問題にもしばらく時間がかかりました. おもしろいことに、私の問題は、暗いホロテーマを選択しながら、明るい色の検索ボタン画像を使用したことです。したがって、私の検索ボタンは、暗い背景では見えなくなります (そこにあります)。同じ問題が発生した場合は、テーマを調整してみてください。

于 2014-02-25T07:51:01.723 に答える