【问题标题】:Search Icon Not Showing Up Where It Needs To搜索图标未显示在需要的位置
【发布时间】:2015-09-14 01:07:06
【问题描述】:

我正在处理一个搜索图标。代码如下:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:MyFirstApp="http://schemas.android.com/apk/res-auto">
    <!-- Search, should appear as action button -->
    <item android:id="@+id/action_search"
        android:icon="@drawable/ic_action_search"
        android:title="@string/action_search"
        MyFirstApp:showAsAction="ifRoom" />
    <!-- Settings, should always be in the overflow -->
    <item android:id="@+id/action_settings"
        android:title="@string/action_settings"
        MyFirstApp:showAsAction="never" />
</menu>

当我运行此代码时,没有显示图标应该在的位置。操作栏上应该有一个图标。我一直遇到代码问题 android:id="@+drawable/ic_action_search"

我做错了什么?

这是我的 MainActivityActions.java 文件:

package com.tyler.snux.myfirstapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivityActions extends AppCompatActivity {

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is     present.
        getMenuInflater().inflate(R.menu.menu_main_activity_actions, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

【问题讨论】:

    标签: android search android-actionbar icons


    【解决方案1】:

    您很可能没有在正确的 actionBar 菜单中夸大它。

    你从哪里引用这个xml,你能发布更多代码以便我可以用正确的代码编辑它吗?

    【讨论】:

    • 我知道应该有一个特定的 .png 或 .gif 文件与此代码一起使用,对吧?我只是无法让它工作
    猜你喜欢
    • 1970-01-01
    • 2021-07-07
    • 2022-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-29
    • 1970-01-01
    • 2021-09-24
    相关资源
    最近更新 更多