0

My layout is like below and I don't want the edittext2 to show above the keyboard when I type in the edittext1(not the keyboard, just the edittext2). And maintain the current status when type in the edittext2

enter image description here

xiaohanhan
  • 25
  • 5

2 Answers2

0

Remove this line from your manifest file.

android:windowSoftInputMode="adjustPan"
0

try this:

Add java class

 @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;
}

Another solution

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();
Android Geek
  • 8,956
  • 2
  • 21
  • 35
  • Thank you, but it makes no sense.I just want to hide the edittext2 when i type something in the edittext1, not hide the keyboard, just hide the edittext2. – xiaohanhan Apr 20 '18 at 13:41