Automatic popping up keyboard on start Activity

后端 未结 19 990
醉梦人生
醉梦人生 2020-11-28 23:05

I got a relative simple question. I have an activity with a lot of EditText\'s in them. When I open the activity it automatically focusses to the first EditText and displays

相关标签:
19条回答
  • 2020-11-28 23:49
    ((InputMethodManager)getActivity().getSystemService("input_method")).hideSoftInputFromWindow(this.edittxt.getWindowToken(), 0);
    
    0 讨论(0)
  • 2020-11-28 23:49

    Add below code to your top of the activity XML and make sure the View is above EditText

    <View 
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:focusableInTouchMode="true"/>
    
    0 讨论(0)
  • 2020-11-28 23:49

    android:focusableInTouchMode="true"

    Add the above line to xml of EditText or TextInputLayout which has focus and is causing the softInputKeyboard to pop up.

    This solved the problem for us and now the keyboard doesn't popup

    0 讨论(0)
  • 2020-11-28 23:51

    this is the solution I am using, is not the best solution but it's working well for me

     editComment.setFocusableInTouchMode(false);
     editComment.setOnTouchListener(new OnTouchListener(){
    
                    @Override
                    public boolean onTouch(View v, MotionEvent event)
                    {
                        // TODO Auto-generated method stub
                        editComment.setFocusableInTouchMode(true);
                         editComment.requestFocus() ;
                        return false;
                    }});
    
    0 讨论(0)
  • 2020-11-28 23:51

    This has some good answers at the following post : Stop EditText from gaining focus at Activity startup. The one I regularly use is the following code by Morgan :

    <!-- Dummy item to prevent AutoCompleteTextView from receiving focus -->
    <LinearLayout
        android:focusable="true" 
        android:focusableInTouchMode="true"
        android:layout_width="0px" 
        android:layout_height="0px"/>
    
    <!-- :nextFocusUp and :nextFocusLeft have been set to the id of this component
    to prevent the dummy from receiving focus again -->
    <AutoCompleteTextView android:id="@+id/autotext"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:nextFocusUp="@id/autotext"     
        android:nextFocusLeft="@id/autotext"/>
    

    NOTE : The dummy item has to be PLACED RIGHT BEFORE the focusable element.

    And I think it should work perfectly even with ScrollView and haven't had any problems with accessibility either for this.

    0 讨论(0)
  • search_edit_text = (EditText) findViewById(R.id.search_edit_text);

        search_edit_text.requestFocus();
        search_edit_text.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN , 0, 0, 0));
        search_edit_text.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP , 0, 0, 0));
    

    This works for me guys fragment may have some different syntax . THIS WORKS FOR ACTIVITY

    0 讨论(0)
提交回复
热议问题