java - 如何删除工具栏左侧显示的默认菜单按钮?
问题描述
我正在尝试删除出现在工具栏左侧的默认菜单按钮,以便可以将其替换为自定义按钮。
这是我的工具栏的 XML 文件:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
tools:context="MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/AppBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="@color/colorPrimary">
<TextView
android:id="@+id/appBarTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:letterSpacing="0.5"
android:text="@string/toolbar_title"
android:textColor="@color/black"
android:textSize="24sp"
tools:ignore="MissingPrefix" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/content_main" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
这是content_main.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="MainActivity"
tools:showIn="@layout/toolbar">
</androidx.constraintlayout.widget.ConstraintLayout>
解决方案
如果您想要具有可自定义选项的基于工具栏的设计,您可以根据您的兴趣继续使用 AppBarLayout 包装相对布局或任何其他布局。在这种情况下处理要容易得多
推荐阅读
- udp - coTURN 无法在 Mozilla Firefox 中进行握手
- arrays - 使用数组改变 Excel 公式中偏移量中的行/列
- python - 当应用程序部署在 AWS Beanstalk 上时,Flask catch-all 端点不再工作
- sql - 如何使用 REGEXP-SUBSTR
- ios - 快速从对象数组中删除某些对象
- c# - 如果在 UserControl 上使用 DataTemplate,WPF DependencyProperty OnPropertyChanged 将默认值返回为 NewValue
- apache-kafka - 提交偏移量时,kafka 流会超时
- php - 我已经使用 php 将 csv 导入到表中,但遇到了问题?
- amazon-web-services - 如何在不传递应用程序中的访问密钥和密钥的情况下访问 aws QLDB?
- java - 在 Spring Boot 应用程序中从 mongo db 获取数据,其中要获取的集合名称和字段在运行时是已知的