【问题标题】:How do I change the color of the ActionBar with sliding drawer?如何使用滑动抽屉更改 ActionBar 的颜色?
【发布时间】:2018-08-30 08:04:15
【问题描述】:

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

如何让操作栏颜色统一?

编辑:这是我的 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


【解决方案1】:

您必须在 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>

【讨论】:

    【解决方案2】:

    如果您是 Android Studio 或一般 Android 的新手,最好使用预先创建的活动。例如,DrawerActivity,它拥有您需要的一切,并且从一开始就看起来很棒。

    只需创建一个新 Activity 并从显示的不同布局中选择它。

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

    我这么说是因为您似乎不明白应该如何将抽屉添加到您的活动中。如果其他人已经为您这样做了,为什么还要重新发明轮子?

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-25
      • 1970-01-01
      • 1970-01-01
      • 2018-08-22
      相关资源
      最近更新 更多