showAsAction =“始终"在工具栏中被忽略 [英] showAsAction = "always" is ignored in Toolbar
问题描述
切换到工具栏后,菜单图标出现问题.尽管我为菜单项android:showAsAction ="always"设置了它,但它不显示图标,但我只能在弹出图标上单击才能找到它.
After switching to toolbar there is a problem with menu icons. Although I set for a menu item android:showAsAction="always" it does not show the icon, I can only find it clicking on the popup icon.
这是myActivity
This is myActivity
public class myActivity extends AppCompatActivity{
.........
public void onCreate(....){
.............
Toolbar toolbar = (Toolbar) findViewById(....);
setSupportActionBar(toolbar);
}
............
public boolean onCreateOptionsMenu(Menu menu{
getMenuInflater().inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}
.............
}
menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/settings"
android:icon="@drawable/settings"
android:title="settings"
android:showAsAction="always"
/>
<item
android:id="@+id/help"
android:icon="@drawable/help"
android:title="help"
android:showAsAction="never"
/>
</menu>
设置和帮助图标仅在弹出菜单中.那么如何在工具栏上显示设置图标呢?
Both settings and help icons are only in popup menu. So how to show settings icon on toolbar?
推荐答案
将android:showAsAction
替换为app:showAsAction
.您还需要在根元素中现有的xmlns
项旁边添加xmlns:app="http://schemas.android.com/apk/res-auto"
.
Replace android:showAsAction
with app:showAsAction
. You will also need to add xmlns:app="http://schemas.android.com/apk/res-auto"
alongside your existing xmlns
item in your root element.
这篇关于showAsAction =“始终"在工具栏中被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!