取消 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上。

 

方法二(未测试):

参考:http://blog.csdn.net/cwc455826074/article/details/6880444?reload

比如我进入一个设置界面,里面如果EditText,那么这时候输入框就会自动弹出,那么如何屏蔽这个输入框呢? 到我们点击EditText的时候才弹出输入框呢?
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS

本人在开发中已经实践过!

 

摘录:http://www.cnblogs.com/duanguyuan/p/4001028.html  @武大-路飞

android开发交流qq群欢迎各位加入(516884181)

 

posted on 2017-04-18 08:52  CallMe_HH  阅读(180)  评论(0编辑  收藏  举报

导航