开发者

How to lock the default keyboard in android?

In my application I want to open the default keyboard when an activity starts and keep it opened until the activity is fini开发者_开发知识库shed.

The reason for this behavior is that I need to add some text in this activity. So, what should I do to accomplish this?


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

if (imm != null){
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
}

use this code in onCreate().


Try this InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(txtBuscar.getId(), InputMethodManager.SHOW_FORCED);

ok you can try this in your mainfeast filr..

<activity android:name=".MainActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateAlwaysVisible" /> 


This will fix

> InputMethodManager imm =
> (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
> imm.toggleSoftInput(txtBuscar.getId(),
> InputMethodManager.SHOW_FORCED);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜