Search code examples
androidandroid-keypad

cursor visibility false not working on hardware back press in android


I have 1 edit text in my activity in that when i press a button soft keyboard opens and on hardware backbutton the softkeyboard is closed and cursor should be visible gone..i have implemented as below..Please help me for it..

public void onBackPressed()
    {


            brand.setCursorVisible(false);
            brand.clearFocus();

        finish();

    }

}

Solution

  • Try this way

    public void onBackPressed()
        {
    
                if(brand.isCursorVisible()){
                    brand.setCursorVisible(false);
                    brand.clearFocus();
                }else{
                    super.onBackPressed();
                }
    
        }