导航抽屉汉堡菜单图标更改问题

问题描述 投票:0回答:0

我无法更改汉堡菜单的默认图标。我正在使用导航组件。这是我在 Home_Activity.kt 文件中尝试的代码

 val navHostFragment =
            supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
        val navController = navHostFragment.navController

        setSupportActionBar(binding.newToolbar)


        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        supportActionBar?.setHomeAsUpIndicator(R.drawable.notification)


        notification = findViewById(R.id.notification)

下面是actiivty_home.xml代码

<androidx.appcompat.widget.Toolbar
        android:id="@+id/new_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="#8049422E"
        android:backgroundTint="#8049422E"
        app:layout_constraintTop_toTopOf="parent"
        app:navigationIcon="@null"
        app:popupTheme="@style/ThemeOverlay.AppCompat.ActionBar">


        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">


            <ImageView
                android:id="@+id/chat"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_marginEnd="18dp"
                android:src="@drawable/ic_chat_main"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toStartOf="@+id/notification"
                app:layout_constraintTop_toTopOf="parent" />

            <ImageView
                android:id="@+id/notification"
                android:layout_width="22dp"
                android:layout_height="22dp"
                android:layout_marginEnd="18dp"
                android:src="@drawable/notification"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@color/white"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent" />


        </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.appcompat.widget.Toolbar>

相关问题图片:

enter image description here

我期望有一个自定义的菜单图标,但每次它都会抛出相同的默认图标

android kotlin navigation-drawer toolbar hamburger-menu
© www.soinside.com 2019 - 2024. All rights reserved.