
Android软键盘强制d出及隐藏输入法的方法:
很多应用中对于一个界面比如进入搜索界面或者修改信息等等情况,为了用户体验应该自动d出软键盘而不是让用户主动点击输入框才d出(因为用户进入该界面必然是为了更改信息)。具体实现这种效果的代码如下:
java代码
EditText editTextsetFocusable(true);
editTextsetFocusableInTouchMode(true);
editTextrequestFocus();
InputMethodManager inputManager =
(InputMethodManager)editTextgetContext()getSystemService(ContextINPUT_METHOD_SERVICE);
inputManagershowSoftInput(editText, 0);
首先要对指定的输入框请求焦点。然后调用输入管理器d出软键盘。
警告:对于刚跳到一个新的界面就要d出软键盘的情况上述代码可能由于界面为加载完全而无法d出软键盘。此时应该适当的延迟d出软键盘如998毫秒(保证界面的数据加载完成)。实例代码如下:
java代码:
Timer timer = new Timer();
timerschedule(new TimerTask()
{
public void run()
{
InputMethodManager inputManager =
(InputMethodManager)editTextgetContext()getSystemService(ContextINPUT_METHOD_SERVICE);
inputManagershowSoftInput(editText, 0);
}
},
998);
String name=usernamegetText()toString();
String pass=passwordgetText()toString();
把它们写到这个监听器的外面来试试。
这样试试。一般来说,android应用程序在d出键盘的时候,如果需要输入的控件靠近下面,为了不被挡住,android系统会自动让整个界面上移至需要输入的控件恰好不被遮住。如果你想要恰好遮挡掉布局A,那么可以把激活键盘的控件恰好放到布局A的上面,而且保证该控件位于整个界面靠近下面的位置(保证键盘d起之后可能会遮住该控件),然后android系统自动调整,就会上移整个界面,且恰好露出该控件,也就会恰好遮住位于该控件下面的布局A了。
private void onCreateIMM() {
InputMethodManager imm = (InputMethodManager) getSystemService(ContextINPUT_METHOD_SERVICE);
mInputMethodProperties = immgetInputMethodList();
mLastInputMethodId = SettingsSecuregetString(getContentResolver(),
SettingsSecureDEFAULT_INPUT_METHOD);
PreferenceGroup textCategory = (PreferenceGroup) findPreference("text_category");
int N = (mInputMethodProperties == null 0 : mInputMethodProperties
size());
for (int i = 0; i < N; ++i) {
InputMethodInfo property = mInputMethodPropertiesget(i);
String prefKey = propertygetId();
CharSequence label = propertyloadLabel(getPackageManager());
boolean systemIME = isSystemIme(property);
// Add a check box
// Don't show the toggle if it's the only keyboard in the system, or it's a system IME
if (mHaveHardKeyboard || (N > 1 && !systemIME)) {
CheckBoxPreference chkbxPref = new CheckBoxPreference(this);
chkbxPrefsetKey(prefKey);
chkbxPrefsetTitle(label);
textCategoryaddPreference(chkbxPref);
mCheckboxesadd(chkbxPref);
}
// If setting activity is available, add a setting screen entry
if (null != propertygetSettingsActivity()) {
PreferenceScreen prefScreen = new PreferenceScreen(this, null);
String settingsActivity = propertygetSettingsActivity();
if (settingsActivitylastIndexOf("/") < 0) {
settingsActivity = propertygetPackageName() + "/" + settingsActivity;
}
prefScreensetKey(settingsActivity);
prefScreensetTitle(label);
if (N == 1) {
prefScreensetSummary(getString(Rstringonscreen_keyboard_settings_summary));
} else {
CharSequence settingsLabel = getResources()getString(
Rstringinput_methods_settings_label_format, label);
prefScreensetSummary(settingsLabel);
}
textCategoryaddPreference(prefScreen);
}
}
}
以上就是关于android输入法是怎样调用的全部的内容,包括:android输入法是怎样调用的、android 对话框 如何 获取输入框值、android如何获取输入法高度,急!!!等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)