2
我嘗試添加菜單在toolbar.i中寫了一些代碼,但我有非常奇怪的情況。我無法看到菜單圖像右側在我的工具欄中,但是當我點擊它時(我的意思是對的側欄),顯示菜單時 這是我的源菜單圖標不在工具欄中顯示
<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="com.unipay.business.activities.MainActivity">
<item
android:id="@+id/transaction_all"
android:orderInCategory="100"
android:title="@string/history_all"
app:showAsAction="never" />
<item
android:id="@+id/transaction_Income"
android:orderInCategory="100"
android:title="@string/history_income"
app:showAsAction="never" />
<item
android:id="@+id/transaction_Outcome"
android:orderInCategory="100"
android:title="@string/u_history_outcome"
app:showAsAction="never" />
<item
android:id="@+id/transaction_advanced_search"
android:orderInCategory="100"
android:title="@string/u_history_advance"
app:showAsAction="never" />
我將ty創建這樣的菜單
這是我的自定義工具欄佈局XML代碼
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/u_common_header_height"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ToolbarTheme"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleTextAppearance="@style/Toolbar.TitleText">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/u_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/u_sign_open_menu_margin"
android:padding="@dimen/u_sign_open_menu_margin"
android:src="@mipmap/ic_arrow_back_white" />
<ImageView
android:id="@+id/logo_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@mipmap/logo_header"
android:visibility="gone" />
<TextView
android:id="@+id/header_tittle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="72dp"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="@dimen/u_common_text_size" />
</RelativeLayout>
我初始化我的工具欄這樣
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
這是一個工具欄風格
<style name="ToolbarTheme" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<!-- android:textColorPrimary is the color of the title text in the Toolbar -->
<item name="android:textColorPrimary">@android:color/holo_blue_light</item>
<!-- actionMenuTextColor is the color of the text of action (menu) items -->
<item name="actionMenuTextColor">@android:color/holo_green_light</item>
<!-- Tints the input fields like checkboxes and text fields -->
<item name="colorAccent">@color/colorPrimary</item>
<!-- Applies to views in their normal state. -->
<item name="colorControlNormal">@color/colorPrimary</item>
<item name="colorControlActivated">@color/colorPrimary</item>
<item name="colorControlHighlight">@color/colorPrimary</item>
</style>
<style name="Toolbar.TitleText" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">21sp</item>
<item name="android:textStyle">italic</item>
</style>
誰能告訴我什麼,我做錯了什麼?正如我所說的菜單工具欄工作,但我不能看到菜單圖像 感謝
檢查此鏈接的http:// stackoverflow.com/questions/19750635/icon-in-menu-not-showing-in-android – ShivBuyya