gpt4 book ai didi

android - 菜单图标未显示在工具栏中

转载 作者:行者123 更新时间:2023-12-05 04:13:01 24 4
gpt4 key购买 nike

我尝试在工具栏中添加菜单。我写了一些代码,但情况很奇怪。我在工具栏右侧看不到菜单图像,但是当我单击它时(我的意思是工具栏右侧)菜单是显示这是我的来源

<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" />

我想创建这样的菜单

enter image description here

这是我自定义的工具栏布局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>

谁能告诉我我做错了什么?正如我所说,菜单在工具栏中工作,但我看不到菜单图像谢谢

最佳答案

try this

import android.support.v7.view.menu.MenuBuilder;

@SuppressLint("RestrictedApi")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (menu instanceof MenuBuilder) {
((MenuBuilder) menu).setOptionalIconsVisible(true);
}
getMenuInflater().inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}

关于android - 菜单图标未显示在工具栏中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38782640/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com