如何在片段启动时打开键盘?我已经试过这个代码:如何在片段中打开键盘
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view =inflater.inflate(R.layout.mylayout,container,false);
TextView TVLarghezza = (TextView) view.findViewById(R.id.larghezza);
TVLarghezza.requestFocus();
InputMethodManager imgr = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imgr.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
return view;
}
但它不起作用。我必须在启动时打开键盘。
我已经已经尝试过这种方法,但他们只在活动上工作,而不是在片段 – Damien
@Damien,我已经更新了答案 – Alexander