Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 为什么操作栏上没有显示操作图标_Android_Android Actionbar_Icons_Overflow_Action - Fatal编程技术网

Android 为什么操作栏上没有显示操作图标

Android 为什么操作栏上没有显示操作图标,android,android-actionbar,icons,overflow,action,Android,Android Actionbar,Icons,Overflow,Action,我开发了android应用程序,我想创建一个放在动作栏上的动作,这个动作可以作为图标显示。我添加了一个分辨率为18x18px的drawable,并创建了一个菜单项,这是我的操作,如下所示: <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android

我开发了android应用程序,我想创建一个放在动作栏上的动作,这个动作可以作为图标显示。我添加了一个分辨率为18x18px的drawable,并创建了一个菜单项,这是我的操作,如下所示:

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

<item
    android:id="@+id/action_show_profile"
    android:icon="@drawable/profile_icon_16"
    android:title="@string/action_show_profile"
    app:showAsAction="always" />
该操作出现在溢出下拉列表中,就好像图标没有空间一样。

使用此选项

Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
还有这个方法

 @Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.YOUR_MENU_FILE, menu);
    return true;
}

我的活动扩展了活动类而不是AppCompatActivity,因此我无法使用GetSupportActionBar()函数,但我尝试了getActionBar(),但它不起作用。如果使用此代码有任何问题,请告诉我。非常感谢。
 @Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.YOUR_MENU_FILE, menu);
    return true;
}
implements AppCompatCallback

and use this code inside oncreate method

  //let's create the delegate, passing the activity at both arguments (Activity, AppCompatCallback)
        AppCompatDelegate  delegate = AppCompatDelegate.create(this, this);

        //we need to call the onCreate() of the AppCompatDelegate
        delegate.onCreate(savedInstanceState);

        //we use the delegate to inflate the layout
        //delegate.setContentView(R.layout.activity_sync_contact);


        toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setNavigationIcon(R.drawable.ic_menu);// icon of navigation 
        toolbar.setTitle("Inbox");
        delegate.setSupportActionBar(toolbar);