单击edittext时,不允许在键盘上方显示edittext

时间:2018-04-19 02:42:25

标签: android

我的布局如下所示,当我输入edittext1(不是键盘,只是edittext2)时,我不希望edittext2显示在键盘上方。在edittext2中键入时保持当前状态

enter image description here

2 个答案:

答案 0 :(得分:1)

从清单文件中删除此行。

android:windowSoftInputMode="adjustPan"

答案 1 :(得分:0)

试试这个:

添加java类

 @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_edit_name, container);
    editText = (EditText) view.findViewById(R.id.txt_yourName);

    // Request focus and show soft keyboard automatically
    editText.requestFocus();
    getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);

    return view;
}

另一种解决方案

editText.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            editText.post(new Runnable() {
                @Override
                public void run() {
                    InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
                }
            });
        }
    });
    editText.requestFocus();