1

As you can see from the screenshot when i open the Keyboard the back button changes to a new action to close the Keyboard. Is there a way to disable this by code and show the On-screen back button instead?

I searched around but i couldn't find the answer.

Thanks

enter image description here

Tasos
  • 5,263
  • 1
  • 13
  • 26
Shubham Chauhan
  • 719
  • 2
  • 6
  • 17

2 Answers2

2

Have you tried this?

you can override the back button on activity

@Override
public void onBackPressed() {
    super.onBackPressed();
}

UPDATE

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);


    // Checks whether a hardware keyboard is available
    if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
        Toast.makeText(this, "keyboard visible", Toast.LENGTH_SHORT).show();
    } else if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
        Toast.makeText(this, "keyboard hidden", Toast.LENGTH_SHORT).show();
    }
}
NaviRamyle
  • 3,827
  • 1
  • 28
  • 49
  • #NaviRamyie This is for back button i am asking when the keyboard is open back button is changes into key down button can we override that key or not? – Shubham Chauhan Sep 24 '15 at 07:58
  • I think he don't need this. The problem is different. –  Sep 24 '15 at 08:14
  • #Shrenik i have tried this also but still toast is not showing.i just want a callback response when the key board is going down and at that time i have to show a tab..please help me in this – Shubham Chauhan Sep 24 '15 at 08:29
  • @ShubhamChauhan so you want to know if the keyboard is open or not. http://stackoverflow.com/questions/25216749/softkeyboard-open-and-close-listener-in-an-activity-in-android – NaviRamyle Sep 24 '15 at 09:01
  • #Shrenik Can you please give me your email id i will mail you the screen shot.Here i cant be able add the image because of low reputation. – Shubham Chauhan Sep 24 '15 at 09:59
2

you can achieve this by creating custom EditText and overriding dispatchKeyEventPreIme() there.

public class CustomEditText extends EditText {

    public CustomEditText(Context context) {
        super(context);
    }

    public CustomEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomEditText(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean dispatchKeyEventPreIme(KeyEvent event) {

        // your logic here

        return super.dispatchKeyEventPreIme(event); // or return true if you don't want the keyboard to be hidden by system
    }
}
DmitryArc
  • 4,277
  • 2
  • 31
  • 37