1

enter image description here

I have one Activity which contain one Edittext, On launching App Edittext come with Soft keyboard, As shown in above figure

enter image description here

Now on First back press button I need to display a dilog box.Normally that dialog appear on second back press. As shown above. But image should come with first screen. Please help me.

3 Answers3

0

You have to write this code in the onCreate method, so that when your app launches, SoftKeboard is not displayed:

this.getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Jamal
  • 763
  • 7
  • 22
  • 32
ishu
  • 1,322
  • 1
  • 11
  • 15
0

Regarding how you can intercept the back button's key event, read this question

After you implement the code to intercept your event, it's a trivial matter to show a dialog on the first click and dispatch the event (let it occur normally) in the second.

Community
  • 1
  • 1
npace
  • 4,218
  • 1
  • 25
  • 35
0
@Override
public void onBackPressed() {
     InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
     inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
     //And Show Dialog  
}
zapdroid
  • 562
  • 5
  • 16