I created a custom keyboard in my application using a keyboard tag. I add this keyboard to RelativeLayout on my screen.
private void createCustomKeyboard() { Keyboard customKeyboard = new Keyboard(getActivity(), R.layout.keyboard); CustomKeyboard mCustomKeyboard = new CustomKeyboard(getActivity(), this); mCustomKeyboard.setKeyboard(customKeyboard); RelativeLayout relLayKeyboard.addView(mCustomKeyboard); }
If you want to use this CustomKeyboard on one or more EditText, you should use the code below:
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; } };
Satya source share