TextInputLayout使用如何实现点击才获取焦点

前几天在项目中用到TextInputLayout来实现用户登录界面,有些细节还是要说说的。

默认我们创建的TextInputEditText获取焦点的状态:如下图

在这里插入图片描述
这不是我想要的结果,我需要的是我点击再获取焦点,不点击之前是没有获取焦点的状态。后来发现了一个属性focusableInTouchMode,兴奋的赶紧放上去试试,结果还是没有达到预期的效果。就在快放弃的时候,我把它加在了TextInputEditText的外层布局TextInputLayout上面,意想不到的结果发生了,尽然实现了我的效果,如图:
在这里插入图片描述

xml布局:

 <android.support.design.widget.TextInputLayout
            android:id="@+id/textlayout_username_login"
            android:layout_width="match_parent"
            android:layout_height="@dimen/dp_49"
            android:imeOptions="actionNext"
            app:counterMaxLength="32"
            android:focusableInTouchMode="true"
            app:hintTextAppearance="@style/login_hintAppearance">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/et_username_login"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginBottom="@dimen/dp_4"
                android:background="@drawable/login_et_selector_bg"
                android:hint="@string/login_text_hint_username"
                android:inputType="text"
                android:lines="1"
                android:singleLine="true"
                android:textColor="@color/color_605F65"
                android:textCursorDrawable="@drawable/login_et_cursor_color"
                android:textSize="@dimen/sp_16" />

        </android.support.design.widget.TextInputLayout>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值