无法在碎片类中解析方法getSystemservice



我如何在片段类中使用getSystemservice,例如以下代码

final EditText input = new EditText(getContext());
InputMethodManager imm = (InputMethodManager)  getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT);
// Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_CLASS_TEXT);
//Show Automatic KeyBoard
input.postDelayed(new Runnable() {
    @Override
    public void run() {
        InputMethodManager keyboard = (InputMethodManager) getBaseContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        keyboard.showSoftInput(input, 0);
    }
}, 50);
builder.setView(input);

使用 getActivity().getSystemService

相关内容

最新更新