如何使用滑动抽屉更改ActionBar的颜色?

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

我在活动中添加了一个滑动抽屉,但它改变了操作栏的一部分的颜色

如何使动作条颜色均匀?

编辑:这是我的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>
android android-actionbar slidingdrawer
2个回答
0
投票

您必须在AppBarLayout中为ref设置颜色。请检查下面的代码

<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
投票

如果您不熟悉Android Studio或Android,则最好使用预先创建的活动。例如,DrawerActivity,它拥有您需要的一切,从一开始就看起来很棒。

只需创建一个新活动,然后从显示的不同布局中选择它。

如果这样做,您只需更改资源/值/颜色中的颜色。

我这样说是因为你看起来不明白你应该如何为你的活动添加抽屉。如果其他人已经为你做了这个,为什么要重新发明轮子?

如果您不想这样做,请查看https://developer.android.com/training/implementing-navigation/nav-drawer

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