我无法获得图标显示与或不使用标题文本使用AppCompat工具栏。标题文本看起来很好,但是根本没有显示任何图标。
图标和标题文本在menu.xml中使用以下xml定义:
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:context="ui.CreateProfileActivity">
<item
android:id="@+id/create_profile_submit"
android:title="@string/create_profile_submit"
app:icon="@drawable/ic_done_white_24dp"
app:showAsAction="always"/>
</menu>在我的styles.xml中,我显式地将图标颜色设置为白色(工具栏的背景是蓝色的):
<item name="actionBarIconColor">#fff</item>这是用于显示工具栏的toolbar_actionbar.xml:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:theme="@style/ActionBarThemeOverlay"
app:popupTheme="@style/ActionBarPopupThemeOverlay"
android:id="@+id/toolbar_actionbar"
android:background="?attr/colorPrimaryDark"
android:layout_width="match_parent"
android:layout_height="wrap_content" />当我在肖像或风景中启动应用程序时,图标不会出现。
如何让工具栏显示:
编辑: 2014.12.14
我能够通过更新menu.xml“图标”属性来使用"android“而不是"app”来显示图标,而且只有图标。新的xml如下:
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:context="ui.CreateProfileActivity">
<item
android:id="@+id/create_profile_submit"
android:title="@string/create_profile_submit"
android:icon="@drawable/ic_done_white_24dp"
app:showAsAction="always"/>
</menu>我仍然无法在肖像模式下同时显示图标和文本。在景观模式下,这两者都显示出来了。
发布于 2019-07-07 10:34:31
我觉得现在太晚了。但是这个代码很好用。你可以试试这个。
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (menu instanceof MenuBuilder) {
((MenuBuilder) menu).setOptionalIconsVisible(true);
}
getMenuInflater().inflate(R.menu.menu_quran, menu);
return true;
}https://stackoverflow.com/questions/27337970
复制相似问题