如何在点击android中的edittext时显示自定义键盘

2023-11-22

我的应用程序中有一个自定义键盘。问题是如何在单击 edittext 时播放此键盘。我使用 setonfocuschangre 侦听器,现在当 edittext 焦点更改时会出现自定义键盘。但我想在每次单击 edittext 时显示此键盘。我忘记了一个信息将编辑文本放在片段内。


我使用键盘标签在我的应用程序中创建了一个自定义键盘。我正在屏幕上的相对布局中添加此键盘。

private void createCustomKeyboard() {
  Keyboard customKeyboard = new Keyboard(getActivity(), R.layout.keyboard);
  CustomKeyboard mCustomKeyboard = new CustomKeyboard(getActivity(), this);
  mCustomKeyboard.setKeyboard(customKeyboard);
  RelativeLayout relLayKeyboard.addView(mCustomKeyboard);  
} 

如果您想在一个或多个 EditText 上使用此 CustomKeyboard,则必须使用以下代码:

EditText edtxtName = (EditText) v.findViewById(R.id.edtName);
RelativeLayout relLayKeyboard = (RelativeLayout)findViewById(R.id.relLay_keyboard);
edtxtName.setOnTouchListener(exitSoftKeyBoard);

private final OnTouchListener exitSoftKeyBoard = new OnTouchListener() {

@Override
public boolean onTouch(View v, MotionEvent event) {
    InputMethodManager imm = (InputMethodManager) getActivity().getApplicationContext().getSystemService(
            android.content.Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    if(v.equals(edtxtName)){
        edtxtName.requestFocus();
        relLayKeyboard.setVisibility(View.VISIBLE);
    } 
    return true;
  }
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在点击android中的edittext时显示自定义键盘 的相关文章

随机推荐