我有两种 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) 所有的迹象似乎表明我的脚本在Linux环境中完全可以运行,据我所知,唯一让它无法在Windows中工作的是我使用sh,这非常简单:
from sh import convert
convert(inputfile, '-resize', r, '-quality', q, '-strip', outputfile)
Run Code Online (Sandbox Code Playgroud)
这转换为bash行:
convert image.jpg -resize 350x350 -quality 80 -strip ./small/export.jpg
Run Code Online (Sandbox Code Playgroud)
其中r和q变量是任何给定的分辨率或质量.
在Windows中运行它当然会引发错误,因为'sh'在Windows中完全不起作用:(我尝试用不推荐的pbs替换'sh' ,但是没有运气.这是我到目前为止所得到的:
import pbs
pbs.convert('-resize', r, '-quality', q, '-strip', inputfile, outputfile)
Run Code Online (Sandbox Code Playgroud)
引发的错误是:
File "C:\Python27\lib\site-packages\pbs.py", line 265, in _create
if not path: raise CommandNotFound(program)
pbs.CommandNotFound: convert
Run Code Online (Sandbox Code Playgroud)
题:
如何在Windows环境中从我的脚本成功传递这些ImageMagick命令?
我有一个课程列表:
val availableClasses = listOf<Whatever>(
classA(),
classB(),
classC()
)
Run Code Online (Sandbox Code Playgroud)
我使用以下方法从该列表中随机选择一个项目:
private var selection: Whatever = availableClasses.random()
Run Code Online (Sandbox Code Playgroud)
不幸的是,我认为这种方法是在加载列表时实例化列表中包含的每个类。
我希望通过用字符串列表替换类列表来解决这个问题:
val availableClasses = listOf<String>(
"classA",
"classB",
"classC"
)
Run Code Online (Sandbox Code Playgroud)
然后一旦我选择了一个字符串,就只实例化那个字符串;就像是:
private var selection: String = availableClasses.random()
// pseudo-code
val chosenClass = selection.toClass()
Run Code Online (Sandbox Code Playgroud)
我可以使用带有getattr函数的字符串来引用 Python 中的类。
在 Kotlin 中有这样的事情吗?
我也愿意接受更好的方法来解决这个问题。