Tôi có bàn phím tùy chỉnh trong ứng dụng của mình. Câu hỏi là làm thế nào để chơi được bàn phím này khi bấm vào edittext.I sử dụng setonfocuschangre listener, bây giờ custon keyboaed xuất hiện khi tập trung edittext được thay đổi. nhưng tôi muốn hiển thị bàn phím này bất cứ khi nào tôi nhấp vào edittext..một thông tin tôi quên đặt ở đây văn bản nằm trong đoạn.Cách hiển thị bàn phím tùy chỉnh khi nhấp vào edittext trong android
Trả lời
Tôi đã tạo Bàn phím tùy chỉnh trong ứng dụng của mình bằng thẻ Bàn phím. Tôi đang thêm bàn phím này trong một RelativeLayout trên màn hình của tôi như thế nào.
private void createCustomKeyboard() {
Keyboard customKeyboard = new Keyboard(getActivity(), R.layout.keyboard);
CustomKeyboard mCustomKeyboard = new CustomKeyboard(getActivity(), this);
mCustomKeyboard.setKeyboard(customKeyboard);
RelativeLayout relLayKeyboard.addView(mCustomKeyboard);
}
Nếu bạn muốn sử dụng CustomKeyboard này trên một hoặc nhiều hơn một EditText sau đó bạn phải sử dụng mã dưới đây:
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;
}
};
Sử dụng onClickListener
như sau:
edit_text.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
custom_keyboard.open();
}
});
Hoặc bạn có thể làm điều này:
edit_text.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus)
custom_keyboard.open();
else
custom_keyboard.close();
}
});
Sử dụng getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
để vô hiệu hóa bàn phím mặc định và sau đó thiết lập một listener nhấp chuột để hiển thị bàn phím của riêng bạn
cảm ơn sự giúp đỡ của bạn .... – user2512822
Bạn có thể thử một cái gì đó như thế này
edittext.setOnClickListener(new OnClickListener() {
// NOTE By setting the on click listener, we can show the custom keyboard again,
// by tapping on an edit box that already had focus (but that had the keyboard hidden).
@Override public void onClick(View v) {
showCustomKeyboard(v);
}
});
// Disable standard keyboard hard way
// NOTE There is also an easy way: 'edittext.setInputType(InputType.TYPE_NULL)'
// (but you will not have a cursor, and no 'edittext.setCursorVisible(true)' doesn't work)
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);
Để biết thêm thông tin, hãy kiểm tra here
Tôi sẽ cố gắng này cho chắc chắn một thông tin tôi quên đặt ở đây edittext là trong đoạn .. – user2512822
- 1. Bàn phím Android không hiển thị khi nhấp vào đầu vào trong chế độ xem web
- 2. Tự động hiển thị bàn phím tùy chỉnh cho EditText. Android
- 3. Làm cách nào để ẩn bàn phím khi nhấp vào bên ngoài editText?
- 4. Android - phím và bàn phím tùy chỉnh
- 5. Bàn phím Android bao gồm EditText khi tôi nhấp vào lần thứ hai
- 6. cách ẩn bàn phím sau khi nhập EditText trong Android?
- 7. Cách tránh bàn phím ảo che phủ EditText trong android
- 8. Hiển thị bàn phím khi TextView được nhấp vào Mono cho Android
- 9. Bàn phím Android ẩn EditText
- 10. Hiển thị bàn phím phần mềm mà không có EditText
- 11. Làm cách nào để hiển thị bàn phím số trên EditText trong Android?
- 12. Khoảng cách giữa bàn phím và EditText trong Android
- 13. android edittext xóa tiêu điểm sau khi nhấp vào nút
- 14. Android: EditText và Button; khi nhấp vào nút, không tập trung EditText và ẩn bàn phím mềm?
- 15. Ẩn một EditText và hiển thị EditText bằng cách nhấp vào menu
- 16. Cách tạo bàn phím tùy chỉnh
- 17. Tùy chỉnh đề xuất trong bàn phím Android
- 18. Hiển thị biểu tượng cảm xúc tùy chỉnh trong Bàn phím Android
- 19. Bàn phím hiển thị cho EditText trong trình mô phỏng (GenyMotion) Android 4.3
- 20. Bàn phím hiển thị android theo lập trình
- 21. EditText ẩn bằng bàn phím khi android: gravity = "center" - Android
- 22. Cách lấy nét và hiển thị bàn phím mềm khi EditText được hiển thị trên thanh hành động?
- 23. ẩn bàn phím mặc định khi nhấp chuột trong android
- 24. Hiển thị bố cục khi bàn phím mềm mở ra
- 25. Thanh trạng thái hiển thị trên Android khi bàn phím hiển thị
- 26. Nền trắng hiển thị khi bàn phím đóng trên Android
- 27. Đặt Chế độ bàn phím trong bàn phím tùy chỉnh Android
- 28. Android - Điều chỉnh màn hình khi bàn phím bật lên?
- 29. Bàn phím mềm mở sau đó đóng lại khi nhấp vào edittext
- 30. Bàn phím iPhone tùy chỉnh
tôi đã sử dụng OnClickListener để hiển thị popupleyboard của tôi và cũng là da bàn phím trong vòng người nghe. thankx cho sự giúp đỡ của bạn .... – user2512822