Cannot change navigation drawer icon color android

I tried below code but I can’t get the color on navigation icon. This is the code below.

Main Activity:

    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setNavigationIcon(R.drawable.ic_menu);
    drawer = findViewById(R.id.drawer_layout);
    NavigationView navigationView = findViewById(R.id.nav_view);
    // Passing each menu ID as a set of Ids because each
    // menu should be considered as top level destinations.
    mAppBarConfiguration = new AppBarConfiguration.Builder(
            R.id.nav_home, R.id.nav_orders, R.id.nav_withdraw, R.id.nav_myteam, R.id.nav_refer,
            R.id.nav_notice, R.id.nav_message, R.id.nav_add_account, R.id.nav_account_detail, R.id.nav_recharge_record, R.id.nav_withdraw_record,
            R.id.nav_complaints, R.id.nav_aboutus, R.id.nav_signout)
            .setDrawerLayout(drawer)
            .build();
    NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
    NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
    NavigationUI.setupWithNavController(navigationView, navController);


    @Override
    public boolean onSupportNavigateUp() {
         NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
         return NavigationUI.navigateUp(navController, mAppBarConfiguration)
                || super.onSupportNavigateUp();
    }
    

The android new android studio version provided the inbuilt navigation drawer and it is simple too. but i cannot change the color of navigation icon.

Main Activity layout:

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.drawerlayout.widget.DrawerLayout
        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:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:openDrawer="start">
        
        <include
            layout="@layout/navigation_app_bar_main"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
            
        <com.google.android.material.navigation.NavigationView
            android:id="@+id/nav_view"
            style="@style/Theme.MenuText"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:fitsSystemWindows="true"
            app:headerLayout="@layout/navigation_header_main"
            app:menu="@menu/activity_main_drawer" />

    </androidx.drawerlayout.widget.DrawerLayout>

This is the main layout of the main activity.

And blow of the included layout for fragment calling.

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        style="@style/Theme.MenuIcon"
        android:layout_height="match_parent"
        tools:context=".ui.P001aaa.P001bbb.P001ccc.P001ddd.P001eee.P001fff.P001ggg.P001hhh.Activity.Main_Activity">

        <com.google.android.material.appbar.AppBarLayout
            style="@style/Theme.Datas"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                style="@style/Theme.Datas"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize" />

        </com.google.android.material.appbar.AppBarLayout>

        <include layout="@layout/navigation_content_main" />

    </androidx.coordinatorlayout.widget.CoordinatorLayout>
    

from below image You can understand what kind of changeing i want.

I want to change this icon color:

This is the image.

Answer

In this case of new android studio with theme implemented we are just have to declare the style in theme.xml

<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>

<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
    <item name="color">@color/white</item>
</style>

Leave a Reply

Your email address will not be published. Required fields are marked *