Android:在调用onPause()时隐藏或销毁视图
问题描述:
您好在我的片段中使用自定义键盘视图。当过用户轻敲编辑文本我shwoing这种观点Android:在调用onPause()时隐藏或销毁视图
insideEdit.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
mKeyboardViewTolerance = new CustomKeyboard(getActivity(), R.id.keyboardviewtolerance, R.xml.keyboard_layout);
mKeyboardViewTolerance.showCustomKeyboard(insideEdit);
insideEdit.setInputType(InputType.TYPE_NULL);
return false;
}
});
当过用户切换到其他片段,并配到相同的片段和水龙头的观点并没有渲染的EditText。我可以看到视图在那里,但视图在屏幕上不可见。
我试图隐藏它的onPause(),但仍然认为不可见
@Override
public void onPause() {
if(mKeyboardViewTolerance != null && mKeyboardViewTolerance.isCustomKeyboardVisible()){
mKeyboardViewTolerance.hideCustomKeyboard();
}
}
答
尝试使用上的EditText焦点监听。
答
使用此代码,它会解决你的问题:在我的showkeyboard使用相同的()文攻的EditText
View view = this.getCurrentFocus();
if (view != null) {
InputMethodManager mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mInputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
已经...... \t公共无效showCustomKeyboard(视图v){ \t \t mKeyboardView.setVisibility(View.VISIBLE); \t \t mKeyboardView.setEnabled(true); \t \t \t如果(V!= NULL) \t \t \t((InputMethodManager)mHostActivity \t \t \t \t \t .getSystemService(mHostActivity.INPUT_METHOD_SERVICE)) \t \t \t \t \t .hideSoftInputFromWindow(v.getWindowToken() 0); \t} – hari86
可以共享您的自定义键盘类的导入包名称 –
package com.ts.in.android.oring.activity; – hari86