簡體   English   中英

如何清除TextInputLayout中第一個Edittext的焦點,它會自動聚焦並在android中打開鍵盤?

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

我有一個活動。 其布局如下。

<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>

問題是,活動開始時,第一個editText會自動聚焦。 我想在活動開始時清除該焦點。 editText xml中,我嘗試將editText設置為false。 但這會影響我的進一步編碼。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM