ActionBarSherlock Actionbar Customization ? - android

I want to remove the back icon and the application icon from the Actionbar. I am using ActionBarSherlock. I have seen many applications that dont show an application icon or a back button ? Is this the best implementation ?
Kind Regards,

I think by "back" button you mean up button that is used to navigate up the application's structural hierarchy. Anyway hope this piece of code solves your problem if you don't want to keep the app icon on top.
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(true); // if you want to show title on Actionbar

the action bar doesn't have a back button since all android devices should include a back button in some way or another.
what you probably mean is the up button , which should go to the "home page" of the app.
you don't have to use it . it's just a nice thing to have. use setDisplayHomeAsUpEnabled for showing and hiding it .

Related

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.

Setting Navigation Icon on Android ActionBar

So I'm working on adding ActionBarSherlock and the Navigation Drawer to a project that previously implemented a custom (very poorly written) "action bar". Instead of using fragments and a backstack of activities for navigation, some activities show and hide different layouts. (That is, suppose I am in a list mode and then select a button to go into an edit screen. The app currently hides the list layout and shows another layout.).
So I've added actionbar sherlock and a navigation drawer to all the activities. I want to be able to programmatically switch the navigation icon from the 3 lines to the arrow when certain buttons are pressed.
I can't figure out how to do this though. Any ideas?
Thanks!
The solution to this problem is to use the method:
setDrawerIndicatorEnabled(boolean enable)
inside the ActionBarDrawerToggle class.
After:
drawer.setDrawerListener(toggle);
Use this code:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.select);
It depends how wedded you are to built-in actionbar artifacts. You can always redraw the current actionbar by inflating a layout of your choosing, then calling
getSherlockActivity().getSupportActionBar().setDisplayShowTitleEnabled(false);
getSherlockActivity().getSupportActionBar().setDisplayShowHomeEnabled(false);
getSherlockActivity().getSupportActionBar().setDisplayShowCustomEnabled(true);
// Inflate and do whatever you need to your view...
getSherlockActivity().getSupportActionBar().setCustomView(abView);
getSherlockActivity().getSupportActionBar().show();
When you want to go back to your standard (assuming you're using a DrawerLayout to do your navigation drawer), you can just set make a call to setDisplayShowCustomEnabled(false) (re-enable showHome and showTitle as you please).
As far as I know, customization of the back button can only be done via themes. Besides, swapping the drawer icon for the back icon (within the same Activity) doesn't make sense, since users would still be able to access the navigation drawer by sliding the left most edge to the right. It just wouldn't make sense.
If you absolutely need the back icon, then it would make the most sense to make that screen a new Activity since you would indeed be adding another "level" to the stack, which is what the back icon represents.

Android: Sliding Menu Slide only content

I'm using Sliding Menu with ActionBarSherlock in my application. The actionbar and sliding menu works fine, but i want the sliding menu to slide only the content and not the actionbar like the latest version of youtube application.
Is this possible with slidingmenu? If yes, please tell how
Thanks in advance
Below is my code for actionbar and slidingmenu
getSlidingMenu().setSlidingEnabled(true);
getSlidingMenu().setShadowWidthRes(R.dimen.shadow_width);
getSlidingMenu().setShadowDrawable(R.drawable.shadow);
getSlidingMenu().setBehindOffsetRes(R.dimen.actionbar_home_width);
getSlidingMenu().setBehindScrollScale(0.25f);
getSlidingMenu().setFadeDegree(0.35f);
getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
Solution:
setSlidingActionBarEnabled(false);
Reference:
Have a look at example
your final code will look something like this after adding the suggested solution,
getSlidingMenu().setSlidingEnabled(true);
getSlidingMenu().setShadowWidthRes(R.dimen.shadow_width);
getSlidingMenu().setShadowDrawable(R.drawable.shadow);
getSlidingMenu().setBehindOffsetRes(R.dimen.actionbar_home_width);
getSlidingMenu().setBehindScrollScale(0.25f);
getSlidingMenu().setFadeDegree(0.35f);
getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
setSlidingActionBarEnabled(false);
I hope it will be helpful !!
According to the developer on GitHub:
Look at step 1. You have 2 options, SlidingMenu.SLIDING_WINDOW or SlidingMenu.SLIDING_CONTENT.
SLIDING_WINDOW will include the Title/ActionBar in the content section
of the SlidingMenu, while SLIDING_CONTENT does not.
I tried with the solution given . But it does not work.
I am using SherlockActionBar and SlidingMenu together.
It works good when I am not setting anything for setSlidingActionBarEnabled method. But it slides the whole window , I want to make it slide only when content is swiped.
So I called this method : setSlidingActionBarEnabled(false);
This has couple of issues :
This makes the app show a blank white page when it is loaded first. I have multiple tabs shown in action bar , so the first tab is shown as selected but the content is empty.
If I slide when say I am in tab 2 , then the back page (or behind page) content is visible but it also overlaps with what is shown currently on tab2.
Any pointers would be helpful.

Hide App name and it's bar

I've been trying to remove this bar (cant hotlink images, yet, check next link):
http://i.imgur.com/fRvMW.png
But I can't achieve it.
Tried the following:
Added into manifest the following:
android:theme="#android:style/Theme.NoActionBar"
But resulted as crash. Probably because I don't have this "Theme". I can't find out what should I write here.
Also tried to remove manually on each Fragment by Graphical Layout, selecting "No action bar", and it doesn't show up on the "preview" but it's shown in the app, probably because its the wrong place to configure it.
Note that it's with fragments. I searched about doing it by code, but I just found options to do it for activities.
So, my question is: How can I hide the App Action bar?
Edit:
SOLVED
On my code, I've this:
final ActionBar bar = getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
So, just added:
bar.hide();
And everything is working. Even if the tabs names aren't shown, the navigation still works (Swaping right and left for swapping fragments.)
Have you tried this?
ActionBar actionBar = getActionBar();
actionBar.hide();

Can i show Tabs without Action Bar in android 3.0?

I want to show tab in my fragment but not on Action Bar?
Is this possible, any link or code might help??
Thanks in advance
I got the tabs without the rest of the ActionBar by removing the home button and the title, like this:
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
and not overriding:
onCreateOptionsMenu
That way the ActionBar would be empty and Android won't display it.
You can use the tabWidget. In a part of my application, I have a TabActivity where the inner activity uses fragments. So, it is possible. It may not be the best solution, but I had to do what the customer wanted.
It depends what kind of tabs you want to use. In my app I'm using ViewPager together with indicator and it works great, so maybe it will suite you. I hope I've understood your question.

Categories

Resources