I want to build a single-line action bar exactly like in fb, with tabs embedded inside the actionbar in form of icons at center so that when user swipes page the next icon is highlighted.
I'm using HoloEverywhere lib which uses actionbarsherlock internally. I'm aware of actionbar customviews but couldnt figure out how to embed tabs inside the customview.
Please help . If possible please share code sample
Thanks in advance
Just create an xml layout that looks like the Facebook action bar, then do something like this:
ActionBar action = getSupportActionBar();
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.your_header_xml, null);
action.setCustomView(view);
You just have to make the xml, then it should display fine.
Related
I have done practice adding menu on action bar. But for this case I have to add tab in actionbar (not below the actionbar) like below figure:
Please help me to find out the solution. Thanks in advance and sorry for bad English.
For your purpose you can try a simple stuff by creating custom ActionBar like this
You can create custom Action bar like this ..
// gets actionBar reference ..
actionBar = getSupportActionBar();
// This sets custom layout to action bar
actionBar.setCustomView(R.layout.action_provider);
// this is how... .... you get id of layout defined
iv_d = (ImageView) actionBar.getCustomView().findViewById(R.id.action_menu);
Now if you need to show stuff like ActionBar tabs then simply provide background on every layout where each layout contains a text and Image... This will provide a look n feel of ActionBar Tab over ActionBar.
Hope it clears your doubt. Let me know if still you have any concern in same.
Thanks.
This question has been asked (for example, here Using ViewPager with Tabs without actionBar), however the answer there doesn't work. There's some links to Swipey but unfortunately the link is broken too.
The example from Android site EffectiveNavigation uses Actionbar to host the tab fragment, so obviously if I set a .NoActionBar theme, then there's no host. Any different way? Thanks.
Update screenshot of what I want to create, at the top, there's no actionbar.
Update 2 this is from the google example, there's an actionbar on top (titled "Effective navigation), which I want to get rid of
Solution of your problem is already given in http://developer.android.com/
To disableAction-bar Icon and Title, you must do two things:
setDisplayShowHomeEnabled(false); // hides action bar icon
setDisplayShowTitleEnabled(false); // hides action bar title
Follow The Steps given in Using split action bar
Write Following Code in OnCreate()
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.navigation_drawer);
getActionBar().setDisplayShowHomeEnabled(false); // hides action bar icon
getActionBar().setDisplayShowTitleEnabled(false); // hides action bar title
//rest of your code...
}
After Android updated Actionbar to Toolbar there are many changes in Actionbar Tabs.
Please follow below links to create swipable tabs in Andoid.
Design Structure :
Tabs Design Guidelines
Some of the very useful links are below. Please refer to them.
Download sample zip from below link
http://developer.android.com/samples/SlidingTabsBasic/index.html
Or Refer these links
http://www.android4devs.com/2015/01/how-to-make-material-design-sliding-tabs.html
http://www.exoguru.com/android/material-design/navigation/android-sliding-tabs-with-material-design.html
http://www.truiton.com/2015/06/android-tabs-example-fragments-viewpager/
https://guides.codepath.com/android/Google-Play-Style-Tabs-using-TabLayout
This may help you...
You can:
Use a ViewPager with a PagerTabStrip
Use a ViewPager with the TabPageIndicator class from the ViewPagerIndicator library
Use a ViewPager with other third-party tab indicators (e.g., in the "View Pagers" category at the Android Arsenal)
Use a ViewPager and design your own tabbed indicator
Use a FragmentTabHost and skip the swiping part
Along with
getActionBar().setDisplayShowHomeEnabled(false);
getActionBar().setDisplayShowTitleEnabled(false);
Use this as well
getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
I have an application that has action bar sherlock and SlidingMenu integrated in it, the application has only 3 pages, and they're static pages, so no big deal about them. I have one activity and 3 fragments that i am changing when using the sliding menu.
What i want to achieve is something like this image
I want the user to be able to swipe with his finger on the ActionBar, and when that happens i change the fragment that is being displayed.
Note: i got the gesture recogniser from this awesome answer, but i can't seem to find a way to attach it to the ActionBar.
If i could put a View on the action bar and detect swipe on it, that would be great, but how can i do that ?!?
One last thing, how to implement this "Page Control" in android ?!?
So the answer to my question is that i simply created a custom_actionbar.xml, and then i used this to do the following:
View custom = LayoutInflater.from(this).inflate(R.layout.actionbar_custom, null);
getActionBar().setCustomView(custom);
// and you can use the things in the custom action bar like following !!
Button btnLeft = (Button) custom.findViewById(R.id.btnMenu);
Hope it helps someone :)
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.
I've got a problem. I wanted to create something that looks like this:
action bar
Left icon would be a back button (I mean it would return to previous tab, the left one), right icon would be next button (it would go to next tab, the right one). I wanted also to make it repeatedly so when I'm on tab A (there are for example 3 tabs: A, B, C) and when I use right button, go to B, then C, and then again A and so on. The text in the middle would be a name of a tab. I would also like to make it compatible with earlier versions of android (like 2.something).
To achieve this, you need to implement custom action bar.
And to target devices with lower android versions use support library. Action bar is supported only in android versions 2.1 and above, with the help of the library.
Refer below link for setting up action bar.
https://developer.android.com/training/basics/actionbar/setting-up.html
The below piece of code will help you to get more idea on this.
// Inflate your custom layout
final ViewGroup actionBarLayout = (ViewGroup) getLayoutInflater().inflate(
R.layout.action_bar,
null);
// Set up your ActionBar
final ActionBar actionBar = getActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(actionBarLayout);
To create above action bar, use relative layout with two image views for direction buttons, and one textview for tabname. For a better design, avoid using tabs in this case. Use Fragments. On each click of the images, just inflate the fragments, each time.
if (openTabIndex=totalNumofTabs-1) {
//go to Tab index 0
} else {
//go to Tab index openTabIndex+1
}
I never worked with tabs before, but this is one if statement that if absent, you cannot do what you want.