现在的位置: 首页 > 综合 > 正文

android EditText取消自动获取焦点 改善用户体验

2013年10月25日 ⁄ 综合 ⁄ 共 789字 ⁄ 字号 评论关闭

在我们的应用中,有时候一进入一个页面, EditText默认就会自动获取焦点。弹出输入法框,用户体验很不好,那么如何取消这个默认行为呢?

在网上找了好久,有点监听软键盘事件的方法,有调用 clearFouse()方法,但是测试了都不行!在对应的 xml中也找不到相应的属性可以关闭这个默认行为。

后来研究了一下,在其父控件下,添加如下的属性,就可以完美解决:

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

<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:gravity="center_vertical"
        android:orientation="horizontal"
         >

        <EditText
            android:id="@+id/searchedit"
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_weight="1"
            android:background="@drawable/input_background" />

        <ImageView
            android:layout_marginLeft="10dp"
            android:layout_width="30dp"
            android:layout_height="30dp" 
            android:background="@drawable/title_find"
            />
    </LinearLayout>

抱歉!评论已关闭.