我有一个非常具体的问题,即当文本输入框不集中时,如何更改文本框的轮廓。我似乎找不到属性来更改“未聚焦”文本框边框的颜色。
这是我要执行的操作的直观示例:
此(文本框):边框的颜色不是白色。目前还没有集中。单击它后,它变成白色:
我不知道需要更改什么,似乎没有属性可以更改它。
我也使用了材质设计文本输入布局样式,尽管我看不到是否会影响它。
这是我的文本框的xml代码:
<other layouts ... >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_gravity="bottom"
android:layout_margin="5dp"
android:background="@drawable/item_recycler_view">
<android.support.design.widget.TextInputLayout
android:id="@+id/dialog_text_input_layout"
style="@style/Widget.AppTheme.TextInputLayoutList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Quick Add..."
android:textColorHint="@color/colorWhite"
app:boxStrokeColor="@color/colorWhite"
app:errorEnabled="true"
>
<android.support.design.widget.TextInputEditText
android:id="@+id/dialog_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:maxLines="1"
android:textColor="@color/colorWhite"
android:textSize="14sp" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
</other layouts...>
这是我为此使用的样式:
<style name="TextAppearance.AppTheme.TextInputLayout.HintTextAlt" parent="TextAppearance.MaterialComponents.Subtitle2">
<item name="android:textColor">@color/colorWhite</item>
</style>
<style name="Widget.AppTheme.TextInputLayoutList" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="hintTextAppearance">@style/TextAppearance.AppTheme.TextInputLayout.HintTextAlt</item>
<item name="boxStrokeColor">@color/colorWhite</item>
<item name="boxCornerRadiusBottomEnd">5dp</item>
<item name="boxCornerRadiusBottomStart">5dp</item>
<item name="boxCornerRadiusTopEnd">5dp</item>
<item name="boxCornerRadiusTopStart">5dp</item>
<item name="android:layout_margin">5dp</item>
</style>
谢谢,欢迎任何帮助或建议!
如果要在未聚焦模式下为轮廓框设置颜色,而不是默认黑色,则必须在colors.xml
文件中添加此行,以覆盖轮廓框的默认颜色。
照原样复制此行。您可以将颜色更改为所需的颜色。
<color name="mtrl_textinput_default_box_stroke_color">#fff</color>
直到现在为止,它都可以使用,要对TextInputLayout进行更多控制,可以在styles.xml中添加此样式
<style name="TextInputLayoutStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
<item name="boxStrokeColor">#fff</item>
<item name="boxStrokeWidth">2dp</item>
</style>
然后将主题添加到TextInputLayout
android:theme="@style/TextInputLayoutStyle"
哦谢谢!这对我有用!如果我问,您是怎么找到这个的?
@VarunGovind欢迎你,并希望投票这个答案,这真的帮助我,以了解更多信息,你可以看到在github上这一问题的讨论在这里和在color.xml您可以访问更多的默认值,这或访问以获取更多信息。
不为我工作。选中时会更改颜色,但默认颜色保持黑色
如何以编程方式设置相同?
'<color name =“ mtrl_textinput_default_box_stroke_color”>#fff </ color>',但这会将所有TextInputLayout更改为白色,如果我想在singel活动或片段中进行更改怎么办?