SCK*_*SCK 6 android android-dark-theme
我有两种 PNG 变体,一种是绘制的文本为黑色,另一种为白色。默认情况下,在白色背景上,我使用黑色图像变体,但是当启用系统暗模式时,图像在背景中几乎不可见。
启用暗模式时,如何指示我的应用使用备用图像?
图像在活动的 XML 中设置:
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.me.some_app.someActivity">
<ImageView
android:id="@+id/Logo"
android:layout_width="176dp"
android:layout_height="219dp"
android:contentDescription="@string/LogoDescription"
app:layout_constraintBottom_toTopOf="@+id/divider"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/logo_black" />
Run Code Online (Sandbox Code Playgroud)
我通过以下过程解决了这个问题:
app/src/main/res/drawable-night,模仿 处已经存在的路径app/src/main/res/drawable。drawable-night目录中,将名称从 更改logo_white.png为logo.png。drawable目录中的黑色变体图像重命名logo_black.png为logo.pngImageView可绘制引用从更新@drawable/logo_black为@drawable/logo看来Android识别出夜间变体目录并相应地翻转。非常好 :)