我开发了基于Android软键盘示例的自定义软键盘。
我正在处理的问题是当我重新启动设备,并点击Android环境中的EditText时,我的键盘没有显示,我必须转到Android输入设置,更改默认键盘,然后选择我的再次键盘。之后,当我点击EditText时,我的键盘会显示,一切正常,直到下一次设备重启。
这个错误的根源是什么?
清单:
<application android:label="@string/ime_name" >
<service
android:name="com.test.softkeyboard.SoftKeyboard"
android:permission="android.permission.BIND_INPUT_METHOD" >
<intent-filter >
<action android:name="android.view.InputMethod" />
</intent-filter>
<meta-data
android:name="android.view.im"
android:resource="@xml/method" />
</service>
</application>
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" />
我的一些方法:
@Override
public void onCreate() {
super.onCreate();
mWordSeparators = getResources().getString(R.string.word_separators);
}
@Override
public View onCreateCandidatesView() {
mCandidateView = new CandidateView(this);
mCandidateView.setService(this);
return mCandidateView;
// return null;
}
@Override
public View onCreateInputView() {
mInputView = (KeyboardView) getLayoutInflater().inflate(
R.layout.input, null);
mInputView.setOnKeyboardActionListener(this);
mInputView.setKeyboard(loadState());
return mInputView;
}
@Override
public void onDisplayCompletions(CompletionInfo[] completions) {
if (mCompletionOn) {
mCompletions = completions;
if (completions == null) {
setSuggestions(null, false, false);
return;
}
List<String> stringList = new ArrayList<String>();
for (int i = 0; i < (completions != null ? completions.length : 0); i++) {
CompletionInfo ci = completions[i];
if (ci != null)
stringList.add(ci.getText().toString());
}
setSuggestions(stringList, true, true);
}
}
@Override
public void onFinishInput() {
super.onFinishInput();
// Clear current composing text and candidates.
mComposing.setLength(0);
updateCandidates();
// We only hide the candidates window when finishing input on
// a particular editor, to avoid popping the underlying application
// up and down if the user is entering text into the bottom of
// its window.
setCandidatesViewShown(false);
saveState(mCurKeyboard);
// mCurKeyboard = mQwertyKeyboard_Fa;
if (mInputView != null) {
mInputView.closing();
}
}
@Override
public void onInitializeInterface() {
if (mQwertyKeyboard_Fa != null) {
// Configuration changes can happen after the keyboard gets
// recreated,
// so we need to be able to re-build the keyboards if the available
// space has changed.
int displayWidth = getMaxWidth();
if (displayWidth == mLastDisplayWidth)
return;
mLastDisplayWidth = displayWidth;
}
mQwertyKeyboard_Fa = new LatinKeyboard(this, R.xml.qwerty_fa);
mQwertyKeyboard_En = new LatinKeyboard(this, R.xml.qwerty_en);
mSymbolsKeyboard = new LatinKeyboard(this, R.xml.symbols);
mSymbolsShiftedKeyboard = new LatinKeyboard(this, R.xml.symbols_shift);
mSymbolsSimpleKeyboard = new LatinKeyboard(this, R.xml.symbols_simple);
}
@Override
public void onStartInputView(EditorInfo attribute, boolean restarting) {
super.onStartInputView(attribute, restarting);
// Apply the selected keyboard to the input view.
mInputView.setKeyboard(mCurKeyboard);
mInputView.closing();
}