向Android中的工具栏添加图标

问题描述 投票:1回答:2

我正在尝试在我的工具栏右边的经典“垂直三个点”之前添加一个图标,该图标位于我的可绘制目录中。这是我的xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/my_toolbar"
        style="@style/HeaderBar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/_20sdp"
        android:layout_alignParentTop="true"
        android:layout_marginTop="@dimen/_3sdp">

        <item
            android:id="@+id/miCompose"
            android:icon="@drawable/eraser"
            android:title="Compose"
            app:showAsAction="ifRoom"></item>
    </androidx.appcompat.widget.Toolbar>

    <TextView
        android:id="@+id/textList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/my_toolbar"
        android:layout_centerHorizontal="true"
        android:textSize="26dp" />

    <ListView
        android:id="@+id/android:list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/my_toolbar" />

</RelativeLayout>

问题是我在网上收到此错误

android.view.InflateException:二进制XML文件第14行:二进制XML文件第14行:夸大类项目的错误

这是我想在我的应用中重新创建的样式:enter image description here

java android xml toolbar
2个回答
0
投票

是。您可以在菜单方法

中使用图标

设置支持操作栏

  setSupportActionBar(toolbar)

override fun onCreateOptionsMenu(menu: Menu): Boolean {
        val inflater = menuInflater
        inflater.inflate(R.menu.menu_logout, menu)
        return true
    }

-1
投票

请在这里分享您的登录日志吗?

© www.soinside.com 2019 - 2024. All rights reserved.