问题:更改 android 中未聚焦的 TextInputLayout 的边框颜色或框笔划 [英] Issue: change border color or box stroke for unfocused TextInputLayout in android

本文介绍了问题:更改 android 中未聚焦的 TextInputLayout 的边框颜色或框笔划的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常具体的问题,即在 TextInputLayout 未聚焦时更改其文本框的轮廓.我似乎找不到一个属性来更改未聚焦"文本框的边框颜色.

I have a very specific issue for changing the outline of the textbox for TextInputLayout when it's unfocused. I can't seem to find an attribute to change the color for the border of my "unfocused" text box.

这是我正在尝试做的一个视觉示例:

Here's a visual example of what I'm trying to do:

这个(文本框):边框的颜色不是白色.目前它没有重点.我点击它后,它变成白色:

The color of this (textbox):border is not white. currently its not focused. After I click it, it turns white:

不知道要改什么,好像没有属性可以改.

I don't know what I need to change, it doesn't seem like there is an attribute to change it.

我也在使用材料设计文本输入布局样式,虽然我不知道这是否会影响它.

I'm also using material design text input layout styles, although I don't see if that will affect it.

这是我的文本框的 xml 代码:

Here is my xml code for the text box:

 <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...>

以下是我为此使用的样式:

And here are the styles that I use for this:

<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>

谢谢,欢迎任何帮助或建议!

Thanks, any help or suggestions are welcome!

推荐答案

如果要在非聚焦模式下设置轮廓框的颜色而不是默认的黑色,则必须在colors.xml中添加这一行 文件,它将覆盖轮廓框的默认颜色.

If you want to set the color for the outline box in unfocused mode instead of the default black, you have to add this line in colors.xml file which will override the default color for the outline box.

照原样复制这一行.你可以改变你想要的颜色.

<color name="mtrl_textinput_default_box_stroke_color">#fff</color>

直到现在它才能工作,为了对 TextInputLayout 进行更多控制,您可以在 styles.xml 中添加此样式

until now it will work, for more control on TextInputLayout you may add this style in styles.xml

<style name="TextInputLayoutStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
    <item name="boxStrokeColor">#fff</item>
    <item name="boxStrokeWidth">2dp</item>
</style>

然后将主题添加到 TextInputLayout

then add theme to TextInputLayout

android:theme="@style/TextInputLayoutStyle"

这篇关于问题:更改 android 中未聚焦的 TextInputLayout 的边框颜色或框笔划的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆