Nik*_*ddy 1 keyboard android android-manifest
目前我正在根据客户要求开发自定义键盘。除了一个问题之外,一切对我来说都很好。我将分步骤清楚地解释我的问题。
带有编辑文本的屏幕截图:

键盘重叠编辑文本:

如果在清单中的某些情况下已经解决了
<activity android:windowSoftInputMode="adjustPan|adjustResize"> </activity>
Run Code Online (Sandbox Code Playgroud)
Xml代码是
<?xml version="1.0" encoding="utf-8"?>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:horizontalGap="0dp"
android:keyHeight="50dp"
android:keyTextSize="12sp"
android:keyWidth="25%p"
android:labelTextSize="12sp"
android:verticalGap="0dp" >
<Row>
<Key
android:codes="8"
android:keyEdgeFlags="left"
android:keyLabel="1" />
<Key
android:codes="9"
android:keyLabel="2" />
<Key
android:codes="10"
android:keyLabel="3" />
<Key
android:codes="69"
android:keyEdgeFlags="right"
android:keyLabel="-" />
</Row>
<Row>
<Key
android:codes="11"
android:keyEdgeFlags="left"
android:keyLabel="4" />
<Key
android:codes="12"
android:keyLabel="5" />
<Key
android:codes="13"
android:keyLabel="6" />
<Key
android:codes="56"
android:keyEdgeFlags="right"
android:keyLabel="." />
</Row>
<Row>
<Key
android:codes="14"
android:keyEdgeFlags="left"
android:keyLabel="7" />
<Key
android:codes="15"
android:keyLabel="8" />
<Key
android:codes="16"
android:keyLabel="9" />
<Key
android:codes="67"
android:iconPreview="@drawable/sym_keyboard_delete"
android:keyEdgeFlags="right"
android:keyIcon="@drawable/sym_keyboard_delete" />
</Row>
<Row>
<Key
android:codes="7"
android:keyLabel="0"
android:keyWidth="50%p" />
<Key
android:codes="66"
android:keyEdgeFlags="right"
android:keyLabel="Done"
android:keyWidth="50%p" />
</Row>
</Keyboard>
Run Code Online (Sandbox Code Playgroud)
我的Java代码是
public class CustomKeyboardView extends KeyboardView {
public CustomKeyboardView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void showWithAnimation(Animation animation) {
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
setVisibility(View.VISIBLE);
}
});
setAnimation(animation);
}
public class BasicOnKeyboardActionListener implements OnKeyboardActionListener {
private Activity mTargetActivity;
/***
*
* @param targetActivity
* Activity a cui deve essere girato l'evento
* "pressione di un tasto sulla tastiera"
* @param mChangedListener
*/
public BasicOnKeyboardActionListener(Activity targetActivity) {
mTargetActivity = targetActivity;
}
@Override
public void swipeUp() {
// TODO Auto-generated method stub
}
@Override
public void swipeRight() {
// TODO Auto-generated method stub
}
@Override
public void swipeLeft() {
// TODO Auto-generated method stub
}
@Override
public void swipeDown() {
// TODO Auto-generated method stub
}
@Override
public void onText(CharSequence text) {
// TODO Auto-generated method stub
}
@Override
public void onRelease(int primaryCode) {
// TODO Auto-generated method stub
}
@Override
public void onPress(int primaryCode) {
// TODO Auto-generated method stub
}
@Override
public void onKey(int primaryCode, int[] keyCodes) {
long eventTime = System.currentTimeMillis();
KeyEvent event = new KeyEvent(eventTime, eventTime,
KeyEvent.ACTION_DOWN, primaryCode, 0, 0, 0, 0,
KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE);
mTargetActivity.dispatchKeyEvent(event);
}
Run Code Online (Sandbox Code Playgroud)
当在活动中声明时
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));
}
Run Code Online (Sandbox Code Playgroud)
隐藏和显示键盘
/** 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);
}
Run Code Online (Sandbox Code Playgroud)
当我单击 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 );
}
Run Code Online (Sandbox Code Playgroud)
福尔
我的自定义 IME 也遇到了类似的问题,并将以下代码添加到我的 InputMethodService 子类中为我解决了这个问题:
@Override
public void onComputeInsets(InputMethodService.Insets outInsets) {
super.onComputeInsets(outInsets);
if (!isFullscreenMode()) {
outInsets.contentTopInsets = outInsets.visibleTopInsets;
}
}
| 归档时间: |
|
| 查看次数: |
947 次 |
| 最近记录: |