2016-08-25 54 views
0

我一直试图在加载片段(包含edittext)时自动显示键盘并将焦点放在编辑文本上。第一次加载片段时软件键盘不会出现

我已经尝试使用:

 editTextPrice.requestFocus(); 
    InputMethodManager imgr = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); 
    imgr.showSoftInput(getView(), InputMethodManager.SHOW_IMPLICIT); 

但是,这并不工作,我第一次加载片段。焦点被设置,我可以看到光标,但没有出现键盘。如果我关闭这个片段并重新添加,它就会起作用。

如果尝试从post()到推迟处理程序到onResume等等。

有没有人有一个想法可能会导致这种情况发生?

在此先感谢。

问候

+0

试图把editTextPrice代替getView(); – Muddz

+0

@Patric你是如何实现这个功能的? –

回答

0
android:focusable="true" 
android:focusableInTouchMode="true" 

而且

EditText yourEditText= (EditText) findViewById(R.id.yourEditText); 
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT); 
相关问题