【发布时间】: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:outlineAmbientShadowColorandroid:outlineSpotShadowColor
标签: android android-toolbar android-elevation