Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android暗模式:高程不更改曲面颜色_Android_User Interface_Material Design_Android Dark Theme_Android Darkmode - Fatal编程技术网

Android暗模式:高程不更改曲面颜色

Android暗模式:高程不更改曲面颜色,android,user-interface,material-design,android-dark-theme,android-darkmode,Android,User Interface,Material Design,Android Dark Theme,Android Darkmode,我正在遵循谷歌的优秀做法,为我的应用程序制作一个黑暗主题,但我没有看到任何关于如何在视图(按钮、应用程序栏等)上获得提升效果的参考资料。例如,当我将我的应用程序主题设置为 制作一个按钮或卡片,如下所示: <Button android:id="@+id/keypadOne" android:layout_width="0dp" android:layout_height="wrap_content" andr

我正在遵循谷歌的优秀做法,为我的应用程序制作一个黑暗主题,但我没有看到任何关于如何在视图(按钮、应用程序栏等)上获得提升效果的参考资料。例如,当我将我的应用程序主题设置为
制作一个按钮或卡片,如下所示:

        <Button
        android:id="@+id/keypadOne"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@color/surface"
        android:elevation="01dp"
        android:text="@string/one"
        android:textColor="@color/onSurface"
        android:textSize="36sp" />

我希望看到的效果,使对象看起来更轻,因为半透明的白色覆盖在黑暗的主题中使用,以暗示海拔或更接近光源比背景。相反,我的按钮、动作栏等与背景颜色相同,因此不可见

我的问题是:

  • 我是否必须手动实现此立面功能,还是由材质库提供
  • 如果我让Android 10+自动运行,我会在版本9和更早版本上实现向后兼容性的手动解决方案吗
  • 我已经找到了答案。为了在CardView的立面上实现叠加着色效果,必须使用包含此功能的材质库的特殊对象:MaterialCardView。使用此CardView后,将其设置为
    app:cardElevation
    属性更改上面链接的google博客文章中提到的关于黑暗模式的白色覆盖

    例如,我的CardView现在看起来像这样:

        <com.google.android.material.card.MaterialCardView 
    android:id="@+id/testCard" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:elevation="18dp" app:cardCornerRadius="4dp" />
    
    
    
    请注意,此特殊高程属性仅适用于MaterialCardView,尽管其他视图(如工具栏)具有材质版本。

    我找到了。为了在CardView的立面上实现叠加着色效果,必须使用包含此功能的材质库的特殊对象:MaterialCardView。使用此CardView后,将其设置为
    app:cardElevation
    属性更改上面链接的google博客文章中提到的关于黑暗模式的白色覆盖

    例如,我的CardView现在看起来像这样:

        <com.google.android.material.card.MaterialCardView 
    android:id="@+id/testCard" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:elevation="18dp" app:cardCornerRadius="4dp" />
    
    
    

    请注意,此特殊高程属性仅适用于MaterialCardView,尽管其他视图(如工具栏)具有材质版本。

    首先确保使用材质组件库主题和类似于此的DayNight变体

    这将自动更改
    AppBarLayout
    工具栏
    MaterialCardView
    的曲面颜色,但如果要根据其他视图的高程设置此自动曲面颜色更改,请设置

    android:background=“?attr/colorSurface”
    或在
    MaterialCardView
    的情况下,使用此
    app:cardBackgroundColor=“?attr/colorSurface”
    并使用


    android:elevation=“4dp”
    或者在某些情况下没有android名称空间
    elevation=“4dp”
    或者在
    MaterialCardView
    的情况下,使用此
    app:cardElevation=“4dp”

    首先确保您使用的材质组件库主题和
    DayNight
    类似的变体

    这将自动更改
    AppBarLayout
    工具栏
    MaterialCardView
    的曲面颜色,但如果要根据其他视图的高程设置此自动曲面颜色更改,请设置

    android:background=“?attr/colorSurface”
    或在
    MaterialCardView
    的情况下,使用此
    app:cardBackgroundColor=“?attr/colorSurface”
    并使用

    android:elevation=“4dp”
    或者在某些情况下没有android名称空间
    elevation=“4dp”
    或者在
    MaterialCardView
    的情况下使用此
    app:cardElevation=“4dp”