Hiding keyboard after calling new Activity that shows a ProgressDialog

后端 未结 5 1399
误落风尘
误落风尘 2021-02-06 11:43

I\'m having trouble with the on screen keyboard. I have an activity with an EditText which shows the keyboard, and a button to go to a second activity. The second a

相关标签:
5条回答
  • 2021-02-06 12:10

    Write this code in manifest.xml file for 'SecondActivity' Activity.

    <activity name="EditContactActivity"
        android:windowSoftInputMode="stateAlwaysHidden">
        ...
    </activity>
    
    0 讨论(0)
  • 2021-02-06 12:10

    Have you tried:

    InputMethodManager im = (InputMethodManager)
    this.getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    
    im.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(),
    InputManagerMethod.HIDE_NOT_ALWAYS);
    

    This is the code I throw in at points I want to hide the keyboard.

    0 讨论(0)
  • 2021-02-06 12:14

    Solved using a variation of the technique posted by phalt:

    InputMethodManager im = (InputMethodManager) this.getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    im.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    

    This code works correctly during onCreate/onStart/onResume, since doesn't rely on a focused view to get the window token from.

    0 讨论(0)
  • 2021-02-06 12:18

    If In Fragment Class

    @Override
        public void onResume()
        {
            getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
            super.onResume();
            }
    

    If In Activity Class

     @Override
        public void onResume()
        {
            this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
            super.onResume();
            FetchLocation fl = new FetchLocation(mContext, locationResult);
        }
    
    0 讨论(0)
  • 2021-02-06 12:23

    you can use like this also:

    InputMethodManager imm;

    Write below line in onCreate() Method:

    imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    And this line is in onclick of button:

    imm.hideSoftInputFromWindow(arg0.getWindowToken(), 0);

    Example:

    public class FirstActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        findViewById(R.id.button1).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
    
                imm.hideSoftInputFromWindow(arg0.getWindowToken(), 0);
                Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
                startActivity(intent);
            }
        });
    }
    }
    
    0 讨论(0)
提交回复
热议问题