Automatic popping up keyboard on start Activity

2019-01-06 10:27发布

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 the virtual keyboard.

How can I prevent this?

17条回答
\"骚年 ilove
2楼-- · 2019-01-06 10:48

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;
                }});
查看更多
地球回转人心会变
3楼-- · 2019-01-06 10:50

You can add this to your Android Manifest activity:

android:windowSoftInputMode="stateHidden|adjustResize"
查看更多
ゆ 、 Hurt°
4楼-- · 2019-01-06 10:53

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"/>
查看更多
我想做一个坏孩纸
5楼-- · 2019-01-06 10:55

If your view has EditText and Listview then Keyboard will open up by default. To hide keyboard from popping up by default do the following

this.listView.requestFocus();

Make sure you are requesting focus on listview after getting view for editText.

For e.g.

this.listView = (ListView) this.findViewById(R.id.list);
this.editTextSearch = (EditText) this.findViewById(R.id.editTextSearch);
this.listView.requestFocus();

If you do it, then editText will get focus and keyboard will pop up.

查看更多
Bombasti
6楼-- · 2019-01-06 10:56

Use this in your Activity's code:

@Override
public void onCreate(Bundle savedInstanceState) {

getWindow().setSoftInputMode(
   WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

}
查看更多
登录 后发表回答