I want to customize the activity back button in action bar, not in hard key back button. I have overriden the onBackPressed()
method. It works with my emulator back button, but not with action bar back button.
I want it to happen with action bar. How can I do this?
Here is my code:
@Override public void onBackPressed() { Toast.makeText(getApplicationContext(),"Back button clicked", Toast.LENGTH_SHORT).show(); return; }
I have used this toast whether back pressed is working or not but the actual implementation changes like to move back to previous activity. But this is not working with the button present on top of action bar (besides title of the activity).
Please any one could specify me the problem.
Please navigate to Android->Advanced Restrictions->Display Settings. Uncheck the 'Hide navigation bar' option. This will disable the on-screen buttons: back, home and recent apps.
getActionBar(). setDisplayShowHomeEnabled(false); //disable back button getActionBar(). setHomeButtonEnabled(false); In a older android phone, the back button is removed with these two code lines.
I think you want to override the click operation of home button. You can override this functionality like this in your activity.
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: Toast.makeText(getApplicationContext(),"Back button clicked", Toast.LENGTH_SHORT).show(); break; } return true; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With