高程属性在api> = 27时不起作用

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

我在我的AppBarLayout上设置了提升属性,它从api 21到26工作,但阴影没有显示在设备上,模拟器在api> = 27上运行。 AppBarLayout或者提升属性有没有变化?

这是我如何使用代码 -

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.appbar.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:elevation="8dp"
    app:theme="@style/ThemeOverlay.MaterialComponents.Dark">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:popupTheme="@style/ThemeOverlay.MaterialComponents.Light"
        app:theme="@style/ThemeOverlay.MaterialComponents.Dark.ActionBar" />

</com.google.android.material.appbar.AppBarLayout>
android android-toolbar android-appbarlayout android-elevation
2个回答
0
投票
  • 你试过StateListAnimator吗?

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { StateListAnimator stateListAnimator = new StateListAnimator(); stateListAnimator.addState(new int[0], ObjectAnimator.ofFloat(appBarLayout, "elevation", 0.1f)); appBarLayout.setStateListAnimator(stateListAnimator); }

要么

  • 尝试设置背景

android:background="@android:color/white" android:elevation="10dp"

希望它有效!


0
投票

尝试使用带有命名空间的app:elevation属性作为app

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.appbar.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:elevation="8dp"
    app:theme="@style/ThemeOverlay.MaterialComponents.Dark"/>
© www.soinside.com 2019 - 2024. All rights reserved.