2015-12-16 30 views
6

tôi có trường văn bản chỉnh sửa bị tắt khi bắt đầu.Bàn phím hiển thị android theo lập trình

tôi muốn đặt chế độ bật, đặt con trỏ trên bàn phím và bàn phím sẽ hiển thị.

tôi thử mã này. tất cả các công trình - chỉ bàn phím sẽ không được hiển thị.

@Override 
    protected void onCreate(Bundle savedInstanceState{ 
     editText.setEnabled(true); 
     editText.requestFocus(); 
     getSystemService(Context.INPUT_METHOD_SERVICE); 
     imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); 
    } 
+6

thấy điều này http://stackoverflow.com/questions/8991522/how-can-i-set-the-focus-và-hiển thị-bàn phím-trên-my-edittex t-programmatic –

+0

đây là mã giống như mã của tôi – Ghost108

+0

có những câu trả lời khác upvoted.Have bạn đã thử chúng ?? –

Trả lời

13

Đối ẩn bàn phím:

InputMethodManager imm = (InputMethodManager)getSystemService(
    Context.INPUT_METHOD_SERVICE); 
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0); 

Đối với Hiển thị bàn phím:

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); 
0

Bạn có thể sử dụng phương pháp này để hiển thị bàn phím mạnh sau khi gọi requestFocus() trên EditText.

public static void showKeyboard(FragmentActivity activity) { 
     InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); 
     inputMethodManager.toggleSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), InputMethodManager.SHOW_FORCED, 0); 
    } 
5

thử phương pháp showKeyboard tôi

public static void showKeyboard(EditText mEtSearch, Context context) { 
    mEtSearch.requestFocus(); 
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE); 
    imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); 
} 

public static void hideSoftKeyboard(EditText mEtSearch, Context context) { 
    mEtSearch.clearFocus(); 
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); 
    imm.hideSoftInputFromWindow(mEtSearch.getWindowToken(), 0); 


} 
Các vấn đề liên quan