【问题标题】:How to Change Toolbar Elevation Color?如何更改工具栏标高颜色?
【发布时间】:2020-05-09 10:19:44
【问题描述】:

在应用程序中有一个更改主题颜色的选项,根据主题颜色,我正在使用以下行更改工具栏背景的颜色:

toolbar.setBackgroundColor(getResources().getColor(R.color.white));

但是,我找不到任何可以帮助我更改海拔颜色的东西。这是工具栏xml:

<com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:elevation="4dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView
                android:id="@+id/title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginRight="10dp"
                android:layout_toLeftOf="@+id/headset"
                android:ellipsize="end"
                android:maxLines="1"
                android:text="@string/contact_us"
                android:textColor="@color/gray"
                android:textSize="18sp" />

        </RelativeLayout>

    </androidx.appcompat.widget.Toolbar>

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

请告诉我如何以编程方式进行。

【问题讨论】:

  • 工具栏的父级是什么?发布 xml
  • @GaneshPokale 发布了 xml。
  • @FaisalShaikh 从 android API 28 开始,现在您可以更改阴影颜色 android:outlineAmbientShadowColor android:outlineSpotShadowColor

标签: android android-toolbar android-elevation


【解决方案1】:

设置 AppBarLayout 高度

<android.support.design.widget.AppBarLayout
    app:elevation="0dp">

应用主题

  <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
      <item name="colorPrimaryDark">@color/green_tataki</item>
    </style>

【讨论】:

    猜你喜欢
    • 2021-07-19
    • 1970-01-01
    • 2015-04-21
    • 1970-01-01
    • 2016-05-21
    • 1970-01-01
    • 2015-05-11
    • 2019-03-11
    • 1970-01-01
    相关资源
    最近更新 更多