简体   繁体   English

如何清除TextInputLayout中第一个Edittext的焦点,它会自动聚焦并在android中打开键盘?

[英]How to clear the Focus of the First Edittext in TextInputLayout which is automatically focussed and opens keyboard in android?

I have an Activity. 我有一个活动。 And its Layout is as below. 其布局如下。

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="15dp"
    android:background="@drawable/my_profile_background"
    android:orientation="vertical">

        <android.support.design.widget.TextInputLayout
            android:id="@+id/layEdtEmails"
            style="@style/edittextStyle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp">

            <EditText
                android:id="@+id/edtEmail"
                style="@style/edittextStyleHint"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/prompt_email"
                android:inputType="textEmailAddress"
                android:maxLength="50"
                android:maxLines="1"
                android:singleLine="true">
            </EditText>

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:orientation="horizontal">               

                <android.support.design.widget.TextInputLayout
                    android:id="@+id/layEdtPasswords"
                    style="@style/edittextStyle"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp"
                    android:layout_marginTop="5dp">

                    <EditText
                        android:id="@+id/edtPassword"
                        style="@style/edittextStyleHint"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="@string/prompt_password"
                        android:inputType="textPassword"
                        android:maxLength="15" />
                </android.support.design.widget.TextInputLayout>
        </LinearLayout>
    </LinearLayout>

The problem is that, the First editText gets Automatically focussed when Activity Starts. 问题是,活动开始时,第一个editText会自动聚焦。 I want to clear that focus when activity starts. 我想在活动开始时清除该焦点。 In xml of editText I tried to put focusable as false. editText xml中,我尝试将editText设置为false。 But it affects my further coding. 但这会影响我的进一步编码。

在EditText的父级布局中添加android:focusable="true ”和android:focusableInTouchMode="true"元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM