我無法使用AppCompat工具欄獲取帶或不帶標題文本的圖標。標題文字顯示正常,但根本沒有圖標顯示。AppCompat工具欄未在菜單XML中顯示圖標集
的圖標和標題文本在一個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「icon」屬性來使用「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>
我仍然無法獲得圖標和文字,以縱向模式同時顯示。它確實以橫向模式顯示。