第一次不聚焦于EditText

3

我在使用EditText时遇到了显示键盘的问题。我想在屏幕显示后第一时间取消焦点。有没有专家可以帮助我解决这个问题。非常感谢。

1个回答

3

设置父布局的属性

android:focusable="true"  
android:focusableInTouchMode="true"

就像这样:

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/black"
    android:gravity="center_horizontal"

    android:focusable="true"  
    android:focusableInTouchMode="true">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/logo"
        android:background="@drawable/dictionary_logo"/>

    <RelativeLayout 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/searchbar_bg"
        android:gravity="center_vertical">

        <EditText
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:id="@+id/et_search"
           android:background="@null"
           android:hint="Search"
           android:singleLine="true"/>

    </RelativeLayout>

</LinearLayout>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接