Android 自定义键盘重叠编辑文本
目前,我正在根据我的客户要求定制键盘。除了一个问题外,每件事对我都很好。我会分步清楚地解释我的问题Android 自定义键盘重叠编辑文本,android,keyboard,android-manifest,Android,Keyboard,Android Manifest,目前,我正在根据我的客户要求定制键盘。除了一个问题外,每件事对我都很好。我会分步清楚地解释我的问题 我有一个屏幕,在底部由2个编辑文本组成 当我点击Edittext时,键盘工作正常,我 也可以输入值 但我的问题是键盘是重叠的编辑文本,需要 显示 带有编辑文本的屏幕截图: 键盘重叠编辑文本: 如果您在某些场景中工作过,如清单中 <activity android:windowSoftInputMode="adjustPan|adjustResize"> </activity&
<activity android:windowSoftInputMode="adjustPan|adjustResize"> </activity>
当在活动中声明时
private Keyboard mKeyboard;
public CustomKeyboardView mKeyboardView;
private void setCustomKeyBoard(){
mKeyboard = new Keyboard(mContext, R.layout.keyboard);
mKeyboardView = (CustomKeyboardView) findViewById(R.id.keyboard_view);
mKeyboardView.setPreviewEnabled(false);
mKeyboardView.setKeyboard(mKeyboard);
mKeyboardView.setOnKeyboardActionListener(new BasicOnKeyboardActionListener(this));
}
隐藏和显示键盘
/** Make the CustomKeyboard visible, and hide the system keyboard for view v. */
public void showCustomKeyboard( View v ) {
mKeyboardView.setVisibility(View.VISIBLE);
mKeyboardView.setEnabled(true);
if( v!=null ){
((InputMethodManager)mContext.getSystemService(Activity.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}
/** Make the CustomKeyboard invisible. */
public void hideCustomKeyboard() {
mKeyboardView.setVisibility(View.GONE);
mKeyboardView.setEnabled(false);
}
当我点击EditText时,将触发以下方法
registerEditText(R.id.edtStop);
private void registerEditText(int resid) {
// Find the EditText 'resid'
EditText edittext= (EditText)mTradeCommonFieldsView.findViewById(resid);
// Make the custom keyboard appear
edittext.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
mTradeActivity.showCustomKeyboard(v);
}else{
mTradeActivity.hideCustomKeyboard();
}
}
});
edittext.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mTradeActivity.showCustomKeyboard(v);
}
});
// Disable standard keyboard hard way
edittext.setOnTouchListener(new OnTouchListener() {
@Override public boolean onTouch(View v, MotionEvent event) {
EditText edittext = (EditText) v;
int inType = edittext.getInputType(); // Backup the input type
edittext.setInputType(InputType.TYPE_NULL); // Disable standard keyboard
edittext.onTouchEvent(event); // Call native handler
edittext.setInputType(inType); // Restore input type
return true; // Consume touch event
}
});
// Disable spell check (hex strings look like words to Android)
edittext.setInputType( edittext.getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS );
}
Foll我的自定义IME也有类似的问题,将以下代码添加到我的InputMethodService子类中为我解决了这个问题:
@覆盖
计算机Insets(InputMethodService.Insets OutitSets)上的公共void{
超级计算机插图(集合);
如果(!isFullscreenMode()){
OutineSets.contentTopInsets=OutineSets.visibleTopInsets;
}
}
我的自定义IME也有类似的问题,将以下代码添加到我的InputMethodService子类中为我解决了这个问题:
@覆盖
计算机Insets(InputMethodService.Insets OutitSets)上的公共void{
超级计算机插图(集合);
如果(!isFullscreenMode()){
OutineSets.contentTopInsets=OutineSets.visibleTopInsets;
}
}
/** Make the CustomKeyboard visible, and hide the system keyboard for view v. */
public void showCustomKeyboard( View v ) {
mKeyboardView.setVisibility(View.VISIBLE);
mKeyboardView.setEnabled(true);
if( v!=null ){
((InputMethodManager)mContext.getSystemService(Activity.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}
/** Make the CustomKeyboard invisible. */
public void hideCustomKeyboard() {
mKeyboardView.setVisibility(View.GONE);
mKeyboardView.setEnabled(false);
}
registerEditText(R.id.edtStop);
private void registerEditText(int resid) {
// Find the EditText 'resid'
EditText edittext= (EditText)mTradeCommonFieldsView.findViewById(resid);
// Make the custom keyboard appear
edittext.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
mTradeActivity.showCustomKeyboard(v);
}else{
mTradeActivity.hideCustomKeyboard();
}
}
});
edittext.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mTradeActivity.showCustomKeyboard(v);
}
});
// Disable standard keyboard hard way
edittext.setOnTouchListener(new OnTouchListener() {
@Override public boolean onTouch(View v, MotionEvent event) {
EditText edittext = (EditText) v;
int inType = edittext.getInputType(); // Backup the input type
edittext.setInputType(InputType.TYPE_NULL); // Disable standard keyboard
edittext.onTouchEvent(event); // Call native handler
edittext.setInputType(inType); // Restore input type
return true; // Consume touch event
}
});
// Disable spell check (hex strings look like words to Android)
edittext.setInputType( edittext.getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS );
}