How do I change the color of the ActionBar with sliding drawer?

188 Views Asked by At

I added a sliding drawer to my activity but it changed the color of a segment of the action bar

action bar color change

How can I make the action bar color uniform?

edit: Here is my code for the xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout     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/layout_NotesActivity"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v4.widget.DrawerLayout
            android:id="@+id/drawerLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:layout_marginTop="0dp">

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

            <android.support.design.widget.NavigationView
                xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:id="@+id/drawer"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="start"
                android:fitsSystemWindows="true"
                app:itemTextColor="@android:color/background_dark"
                app:menu="@menu/menu_drawer" />


        </android.support.v4.widget.DrawerLayout>

    </RelativeLayout>
2

There are 2 best solutions below

0
X-Byte Technolabs pvt. ltd. On

You have to set color in AppBarLayout for ref. please check code below

<android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar_Drawer"
            android:layout_width="match_parent"
            android:layout_height="?android:attr/actionBarSize"
            android:background="@android:color/transparent"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

            <android.support.v7.widget.AppCompatImageView
                android:layout_width="match_parent"
                android:layout_height="@dimen/_100sdp"
                android:background="@drawable/gradiant_splash"
                android:scaleType="centerCrop" />
    </android.support.design.widget.AppBarLayout>
0
ProgFroz On

If you are new to Android Studio or Android in General, it is a good idea to use the precreated Activities. For example, the DrawerActivity, which has everything you need and looks great from the beginning.

Simply create a new Activity and choose it from the different shown Layouts.

If you do that, you simply need to Change the Colors in the resources/values/colors.

I say that because it Looks like you do not understand the way you should add a Drawer to your activity. Why reinventing the Wheel if someone else already did this for you?

If you do not want to do that, take a look at https://developer.android.com/training/implementing-navigation/nav-drawer