(转)取消 EditText 自动聚焦弹出输入法界面

方法一(实测可行):

参考http://www.cnblogs.com/dream-cichan/p/aaaa.html

当我点击跳转至一个带有EditText的界面后,模拟器中的软键盘会自动弹出,严重影响了用户体验。在网上找了资料,现总结如下。

我们知道,EditText有一个 android:focusable=""的属性,但是如果你在edittext中直接将这个属性设置为true的话,点进去软键盘确实不会再弹出,但是EditText相应的也失去了聚焦,即无论你怎么点击它都不会有反应,这也就失去了EditText的原本的作用。那么要解决这个问题其实很简单,只需在EditText的父控件中加上这两行代码即可:

android:focusable="true" 

android:focusableInTouchMode="true"

示例:

复制代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:focusable="true"
    android:focusableInTouchMode="true" >

    <EditText
        android:id="@+id/editText_search"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:hint="Search" />

    <ListView
        android:id="@+id/questionsListView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

</LinearLayout>
复制代码

我的理解是整个焦点聚在父控件的界面上了,所以也就不会单单聚焦在EditText上。

 

方法二:

//收起键盘
    protected void hideSoftKeyboard()
    {
        if (this.getCurrentFocus() != null)
        {
            InputMethodManager inputMethodManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(),0);
        }
    }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值