前几天在项目中用到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>