Remove default home/up button in action mode - android

I have created custom action mode which visible on long click on list item . There is default back/up button visible in actionMode.
Without change in style.xml , it's possible to remove default action mode back/up button from fragment/activity class.
Kindly help.

Try this,
getActionBar().setDisplayHomeAsUpEnabled(false);
OR
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
this may helps you.

Use the method: getActionBar().setDisplayHomeAsUpEnabled(false) to remove the home button from the action bar.
Example:
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setHomeButtonEnabled(false); // disable the button
actionBar.setDisplayHomeAsUpEnabled(false); // remove the left caret
actionBar.setDisplayShowHomeEnabled(false); // remove the icon
}

You can remove action button home up enabled through ::
if you are using support v7 lib then
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
else
getActionBar().setDisplayHomeAsUpEnabled(false);

Related

Add image to left side of action bar ?

I need add a image in between navigation button and drop-down in action-bar.How can I do this?
you need to call setIcon() it will change the icon
getActionBar();
ActionBar actionBar = getActionBar();
actionBar.setIcon(R.drawable.my_icon);
see this for more detail

Android: Remove activity back Arrow

I created two blank activities in android studio and it looks like it adds back arrow by default. My MainActivity is parent ofResultActivity. I want to maintain this hierarchy but want to get rid of back arrow.
If you're on API level 14 or above and are not using ActionbarSherlock, this code in onCreateOptionsMenu should disable the up button;
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setHomeButtonEnabled(false); // Disable the button
actionBar.setDisplayHomeAsUpEnabled(false); // Remove the left caret
actionBar.setDisplayShowHomeEnabled(false); // Remove the icon
}
If you're using a support lib such as ActionbarSherlock, then use;
getSupportActionBar().setHomeButtonEnabled(false); // Disable the button
getSupportActionBar().setDisplayHomeAsUpEnabled(false); // Remove the left caret
getSupportActionBar().setDisplayShowHomeEnabled(false); // Remove the icon
getActionBar().setDisplayHomeAsUpEnabled(false);
I know this is an old question but I came across this now and had to take some additional action to remove the back arrow.
So in addition to this piece of code as indicated the correct answer
getActionBar().setDisplayHomeAsUpEnabled(false);
you will also need to remove the parent-child relationship in the AndroidManifest.xml file . Your activity should not have the following entry
android:parentActivityName
Might help someone else who stumbles across this one.

hide up button and show icon as home in action bar

actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setHomeButtonEnabled(true);
i have this code to hide title and up button in my code and show only the icon but my problem is when i click on the icon it doesnt work anymore meaning it does not bring me to home activity anymore but when i set actionBar.setDisplayHomeAsUpEnabled(false); to true it works ok any idea on how to make this work the way i want it to work

Remove back arrow in sherlockactionbar

I need to remove the back arrow and keep only the home icon in action bar sherlock library. I set getSupportActionBar().setDisplayHomeAsUpEnabled() to false but it disabled action bar button.
Maybe you forgot to set the home button itself as enabled?
Try this instead:
// Hide the ActionBar's up button
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setHomeButtonEnabled(true);

android: how to remove the back/home button in the action bar

I am having difficulties trying to remove the back/home button from the action bar.
getActionBar().setDisplayShowHomeEnabled(false); //disable back button
getActionBar().setHomeButtonEnabled(false);
In a older android phone, the back button is removed with these two code lines. However with the nexus 4, the back button still appears but is just disabled. Also I am just adding a menu item on the right that behaves like the back/home button replacing the back/home button. What am I missing?
Use getActionBar().setDisplayHomeAsUpEnabled(false) to remove the home button from the action bar.
If you're on API level 14 or above and are not using ActionbarSherlock, this code in onCreateOptionsMenu will disable the up button, remove the left caret, and remove the icon:
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setHomeButtonEnabled(false); // disable the button
actionBar.setDisplayHomeAsUpEnabled(false); // remove the left caret
actionBar.setDisplayShowHomeEnabled(false); // remove the icon
}
source: https://stackoverflow.com/a/24967862/2887103
ElectronicGeeks answer is correct.
For API lower than 11, Use:
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
To control the up affordance, use setDisplayHomeAsUpEnabled().
None of the suggested solutions works for me.
But this one does:
// Hide the back button
mActionBar.setHomeAsUpIndicator(null);
It is a kind of a hack (last resort solution), though, so showing the action bar again means setting its icon back again.
This worked for me :)
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(false);
For Kotlin;
(activity as AppCompatActivity).supportActionBar?.setDisplayHomeAsUpEnable(false)
In the case where you have used toolbar as Action bar:-
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Use the below code to hide the navigation button:-
toolbar.setNavigationIcon(null);
This code work for me
For remove navigation bar
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
For remove status bar
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
ฺBut above code, it show again when you touch on screen, so if you want static state, combine this code.
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE);
You can use this code :
toggle.setDrawerIndicatorEnabled(false);
Works great for me.

Categories

Resources