Prevent the keyboard from displaying on activity start

后端 未结 17 715
轮回少年
轮回少年 2020-11-30 17:26

I have an activity with an Edit Text input. When the activity is initialized, the Android keyboard is shown. How can the keyboard remain hidden until the user

相关标签:
17条回答
  • 2020-11-30 17:47

    You can try this set unique attribute for each element

    TextView mtextView = findViewById(R.id.myTextView);
    mtextView.setShowSoftInputOnFocus(false);
    

    Keyboard will not show while element is focus

    0 讨论(0)
  • 2020-11-30 17:48
    //to hide the soft keyboard
    InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
    
    0 讨论(0)
  • 2020-11-30 17:50

    Add these two properties to your parent layout (ex: Linear Layout, Relative Layout)

    android:focusable="false"
    android:focusableInTouchMode="false" 
    

    It will do the trick :)

    0 讨论(0)
  • 2020-11-30 17:53

    Just Add in AndroidManifest.xml

    <activity android:name=".HomeActivity"  android:windowSoftInputMode="stateHidden">
    </activity>
    
    0 讨论(0)
  • 2020-11-30 17:54

    If you are using API level 21, you can use editText.setShowSoftInputOnFocus(false);

    0 讨论(0)
  • 2020-11-30 17:55

    Best solution for me, paste your class

    @Override
    public void onResume() {
        this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        super.onResume();
    }
    
    @Override
    public void onStart() {
        this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        super.onStart();
    }
    
    0 讨论(0)
提交回复
热议问题