您的位置:首页 > 其它

关于EditText默认会弹出输入法的问题

2015-12-22 15:19 253 查看
最近遇到个问题app启动页面有个EdtiText(下面的edt)每次启动都会打开输入法,很是烦,网上找了下方法

有的说在前面的控件添加下面方法可以截断。。虽然我不知道有没有截断但是,输入框还是弹出来了、、

android:focusable="true"

android:focusableInTouchMode="true"

然后我只能把edt的获取焦点关闭了

android:focusable="false",

然后在edt的点击事件里面添加

edt.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

edt.setFocusable(true);

edt.setFocusableInTouchMode(true);

edt.requestFocus();

edt.requestFocusFromTouch();

}

});



这样虽然是可以但是。要点两下才会弹出来输入框。

然后在网上看到了一片文章。↓第一个在清单文件里面添加的方法我觉得很好用。

第二个方法我试了也不行。

第三个也不行。。我不知道问什么。。

方法一:

  在
AndroidMainfest.xml中选择哪个activity,设置windowSoftInputMode属性为 adjustUnspecified|stateHidden

<
activity android:name=".Main"

android:label="@string/app_name"

android:windowSoftInputMode="adjustUnspecified|stateHidden"

android:configChanges="orientation|keyboardHidden">

<
intent-filter>

<
action android:name="android.intent.action.MAIN" />

<
category android:name="android.intent.category.LAUNCHER" />

<
/intent-filter>

<
/activity>

方法二:

  让
EditText失去焦点,使用EditText的clearFocus方法

  例如:

EditText
edit=(EditText)findViewById(R.id.edit);

  edit.clearFocus();

方法三:

  强制隐藏Android输入法窗口

例如:

EditText
edit=(EditText)findViewById(R.id.edit);

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);

imm.hideSoftInputFromWindow(edit.getWindowToken(),0);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: