Remove back arrow in sherlockactionbar - android

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);

Related

Hamburger Icon Not showing

When I use to change Hamburger Icon to Back Icon while add a new fragment it's Perfectly working. Here is my code
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
supportActionBar!!.setDisplayShowHomeEnabled(true)
But when I press back button and close the fragment then it not change to hamburger icon
supportActionBar!!.setDisplayHomeAsUpEnabled(false)
supportActionBar!!.setDisplayShowHomeEnabled(false)
NOTE: I dont have drawer layout. I use this library: yarolegovich/SlidingRootNav
This is expected behaviour, it won't automatically change when you are doing:
actionBar.setDisplayHomeAsUpEnabled(true);
One solution would be to handle it for yourself. Just change the icon manually
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeAsUpIndicator(R.drawable.back);
and on back pressed, change it to hamburger icon:
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeAsUpIndicator(R.drawable.hamburger_icon);
Hope this helps. Cheers.

Remove default home/up button in action mode

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);

Icon for Up in action bar in Android is an arrow (<-) instead of a arrow head (<)

I have enabled the up button by calling setDisplayHomeAsUpEnabled on getSupportActionBar(). But the icon showing in the action bar is not good compared to the default one.
An arrow icon is appearing as back/up button in the action bar, I was expecting a arrow head only for button default. All the examples in web are showing array head for back /up button.
How to make the icon just arrow head ?
You can change the action bar navigation icon by the below method
actionBar.setHomeAsUpIndicator(R.drawable.your_icon);

Switch from Up Arrow to Hamburger Icon on Button Click in ActionBar

I want to change the Hamburger icon on Android ActionBar to Up arrow on button click, and also to change the Up arrow back to Hamburger icon on another button click event.
I have tried using ,
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
However, none of them works. I can change the Hamburger icon to up arrow easily using,
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
But not the vice-versa.
Also, how do I override the home button control?
I mean when a certain layout is open, I want the up arrow to close that layout on click and not to call the navigation drawer.
Please help.
You could use the following piece of code:
ViewGroup home =(ViewGroup)findViewById(android.R.id.home).getParent();
// get the first child (up imageview)
((ImageView) home.getChildAt(0)).setImageResource(your image here);
Sorry, no privileges to comment so updating the answer. Well, since this is an imageView, I am assuming you could place an onClickListener and toggle between using the hamburger and the back arrow. This should be close to the material design's animated hamburger behavior.

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