gpt4 book ai didi

android - 如何在 TextInputLayout unfocus 中更改边框和颜色?

转载 作者:行者123 更新时间:2023-12-05 00:09:26 33 4
gpt4 key购买 nike

如何在 TextInputLayout unfocus 中更改边框和颜色?

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_height="wrap_content"
app:boxStrokeWidth="4dp"
app:boxStrokeColor="@color/colorPrimary"
app:layout_constraintTop_toBottomOf="@id/a">

<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:hint="@string/app_name"
android:textColorHint="@color/colorPrimary"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>

我试试:

app:boxStrokeWidth="4dp"
app:boxStrokeColor="@color/colorPrimary"

但是,不能在不专心的情况下工作

最佳答案

如果你想在聚焦/非聚焦模式下有不同的笔划宽度,你可以使用 boxStrokeWidthboxStrokeWidthFocused 属性。

<!-- The value to use for the box's stroke when in outline box mode, 
or for the underline stroke in filled mode. -->
<attr format="dimension" name="boxStrokeWidth"/>
<!-- The value to use for the focused box's stroke when in outline box mode,
or for the focused underline stroke in filled mode.. -->
<attr format="dimension" name="boxStrokeWidthFocused"/>

类似于:

    <com.google.android.material.textfield.TextInputLayout
app:boxStrokeWidthFocused="4dp"
app:boxStrokeWidth="1dp"
app:boxStrokeColor="@color/text_input_layout_stroke_color"
..>

对于描边颜色,您可以定义一个选择器,例如:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/..." android:state_focused="true"/>
<item android:alpha="0.87" android:color="@color/..." android:state_hovered="true"/>
<item android:color="@color/.." android:state_enabled="false"/>
<item android:color="@color/..."/> <!--unfocused-->
</selector>

enter image description here enter image description here

注意:boxStrokeWidthFocused 至少需要 1.2.0-alpha04 版本。

关于android - 如何在 TextInputLayout unfocus 中更改边框和颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60079180/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com