包装到 TextInputLayout 时更改 EditText 底线的粗细 [英] Change thickness of the bottom line of EditText when wrapped into TextInputLayout

查看:28
本文介绍了包装到 TextInputLayout 时更改 EditText 底线的粗细的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

XML 标记

(聚焦视图)

现在我的问题/问题

  1. 我希望底线更薄.我应该在哪里改变它.
  2. 闪烁的光标不显示,如何显示.
  3. EditText 会自动突出显示拼写错误.我需要阻止它.

谁能指出解决问题的正确方法.评论你任何人都需要更多信息来回答这个问题.

提前致谢.

解决方案

我已经使用我的自定义 xml drawable 解决了我的问题.可能有更好的方法,但我找不到.以下是我用作文本框背景的可绘制对象

<?xml version="1.0" encoding="utf-8"?><选择器xmlns:android="http://schemas.android.com/apk/res/android"><项目 android:state_pressed="true"><层列表><项目机器人:底部=1dp"机器人:左=-2dp"机器人:右=-2dp"android:top="-2dp"><形状 android:shape="矩形"><中风安卓:宽度=0.5dp"android:color="@color/primaryColor"/><solid android:color="#00FFFFFF"/><填充 android:left="3dp"机器人:右=3dp"机器人:顶部=3dp"android:bottom="3dp"/></形状></项目></层列表></项目><项目 android:state_focused="true"><层列表><项目机器人:底部=1dp"机器人:左=-2dp"机器人:右=-2dp"android:top="-2dp"><形状 android:shape="矩形"><中风安卓:宽度=0.5dp"android:color="@color/primaryColor"/><solid android:color="#00FFFFFF"/><填充 android:left="3dp"机器人:右=3dp"机器人:顶部=3dp"android:bottom="3dp"/></形状></项目></层列表></项目><项目><层列表><项目机器人:底部=1dp"机器人:左=-2dp"机器人:右=-2dp"android:top="-2dp"><形状 android:shape="矩形"><中风安卓:宽度=0.5dp"android:color="#BCBCBC"/><solid android:color="#00FFFFFF"/><填充 android:left="3dp"机器人:右=3dp"机器人:顶部=3dp"android:bottom="3dp"/></形状></项目></层列表></项目></选择器>

here is my code

XML Markup

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/TextLabel">

    <EditText
        android:id="@+id/etContactName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Contact Name"/>

</android.support.design.widget.TextInputLayout>

Style

<style name="TextLabel" parent="TextAppearance.AppCompat">
    <item name="android:textColorHint">@color/hintColor</item>
    <item name="colorAccent">@color/primaryColor</item>
    <item name="colorControlNormal">@color/hintColor</item>
    <item name="colorControlActivated">@color/primaryColor</item>
</style>

Here is the output
(normal view)

(focused view)

Now My Problems / Issues

  1. I want the bottom line to be thinner. where should I change it.
  2. The blinking cursor is not showing, how to show it.
  3. EditText is automatically highlighting the spelling mistakes. I need to stop it.

Can anyone please point me to the right way to resolve the issues. Comment you anyone needs more info to answer this.

Thanks in advance.

解决方案

I've solved my issue using my custom xml drawable. There might be some better way, but I couldn't find any. following is my drawable that I'm using as background of my textbox

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <layer-list >
            <item
                android:bottom="1dp"
                android:left="-2dp"
                android:right="-2dp"
                android:top="-2dp">
                <shape android:shape="rectangle" >
                    <stroke
                        android:width="0.5dp"
                        android:color="@color/primaryColor" />

                    <solid android:color="#00FFFFFF" />

                    <padding android:left="3dp"
                        android:right="3dp"
                        android:top="3dp"
                        android:bottom="3dp" />
                </shape>
            </item>

        </layer-list>
    </item>
    <item android:state_focused="true">
        <layer-list >
            <item
                android:bottom="1dp"
                android:left="-2dp"
                android:right="-2dp"
                android:top="-2dp">
                <shape android:shape="rectangle" >
                    <stroke
                        android:width="0.5dp"
                        android:color="@color/primaryColor" />

                    <solid android:color="#00FFFFFF" />

                    <padding android:left="3dp"
                        android:right="3dp"
                        android:top="3dp"
                        android:bottom="3dp" />
                </shape>
            </item>

        </layer-list>
    </item>
    <item>
        <layer-list >
            <item
                android:bottom="1dp"
                android:left="-2dp"
                android:right="-2dp"
                android:top="-2dp">
                <shape android:shape="rectangle" >
                    <stroke
                        android:width="0.5dp"
                        android:color="#BCBCBC" />

                    <solid android:color="#00FFFFFF" />

                    <padding android:left="3dp"
                        android:right="3dp"
                        android:top="3dp"
                        android:bottom="3dp" />
                </shape>
            </item>

        </layer-list>
    </item>

</selector>

这篇关于包装到 TextInputLayout 时更改 EditText 底线的粗细的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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