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

本文介绍了问题:在Android中更改未聚焦的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天全站免登陆