我希望能够通过编程方式更改TextInputLayout的轮廓线,但似乎无法实现。有一种通过XML进行操作的选项(其他SO用户使用XML提出的问题),但对我来说不可用,因为我需要动态着色。目前我拥有以下布局:
如何动态着色,就像下图所示?
当前情况:
期望情况:(photoshopped)
类似的问题,但集中在XML上
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:id="@+id/color_outline"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/color"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Choose color"/>
</com.google.android.material.textfield.TextInputLayout>
我尝试通过查看 TextInputLayout 的各种框方法来应用颜色,但没有任何效果。
internal fun String.toIntColor() = Integer.parseInt(this.replaceFirst("#", ""), 16)
val colorOutline: TextInputLayout = view.findViewById(R.id.color_outline)
colorOutline.boxStrokeColor = "#006699".toIntColor()
如何动态着色,就像下图所示?
当前情况:
期望情况:(photoshopped)
类似的问题,但集中在XML上