問題描述
我的應用程序中有一個自定義鍵盤.問題是單擊edittext時如何播放此鍵盤.我使用setonfocuschangre偵聽器,現在更改edittext焦點時會出現custon keyboaed.但是我想在單擊edittext時顯示此鍵盤..一個我忘記的信息將edittext放在片段內.
I have a custom keyboard in my application. question is How to didplay this keyboard when click on the edittext.I an using setonfocuschangre listener ,now the custon keyboaed appears when the edittext focus is changed.but i want to show this keyboard whenever i click on the edittext..one info I forget to put here the edittext is within the fragment.
推薦答案
我使用鍵盤標簽在我的應用程序中創建了一個自定義鍵盤.我在屏幕上的 RelativeLayout 中添加了這個鍵盤.
I created a Custom Keyboard in my application using Keyboard tag. I am adding this keyboard in a RelativeLayout on my screen like.
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,那么你必須使用下面的代碼:
If you want to use this CustomKeyboard on one or more than one EditText then you have to use below code :
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;
}
};
這篇關于在android中單擊edittext時如何顯示自定義鍵盤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!