Tabs on Main Section of ActionBar - android

How can i archive a Tab layout like this in Android ? The Tab Navigation is part of that
Main ActionBar and is not below. PS: Im using ActionBar Sherlock
At the moment is just do:
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
But i want a look like this:
Thanks for help,
Kitesurfer

I don't recommend doing this but you could override the ActionBar and ABS styles:
<bool name="abs__action_bar_embed_tabs">false</bool> //for ActionBarSherlock
<bool name="action_bar_embed_tabs">false</bool> //for default ActionBar

Tab will be displayed in actions bar but only if action bar has space. When you are in landscape mode your tabs will move to action bar because in landscape mode action bar has more room.

From this thread. On the topic of overriding the Action Bar tab functionality.
Jake Wharton
I am obligated to tell you this is probably a Bad Idea™ and I don't recommend it. When you fight the platform you almost always end up losing.
I am inclined to agree about fighting the platform. Instead I opted to abandon the stock tab navigation (from both the android platform and ABS library) and instead wrote a layout that looks basically the same as the tabs, and used it as a custom view, applying it using ActionBar.setCustomView(View) and ActionBar.setDisplayShowCustomEnabled(true) methods.
This uses the ActionBar api in the standard way (ie. Not fighting the platform) and, as is pointed out in that thread, the tab view is simply a LinearLayout.

Try this. This implements a method that will let you select whether you want the tabs in a separate row or in the top row, regardless of screen orientation.
For those who are using this code with the native ActionBar, simply omit the if (actionBar instanceof ActionBarWrapper) and the block underneath it.
Bear in mind, though, that this is somewhat of a hack and might break in future Android versions.

Related

What's the difference between ActionBar and create vertical layout for ActionBar

First sry for my amateur question
When we want to make an Actionbar, we can use AppCompat or libs(like ActionBarSherlock & ...), and when we want just add any widget(like Button-ImageView & ...), we have to add a lot of codes...
But we can create vertical layout (height:50dip) in all of Activities and use it as the Actionbar...(It's very simpler than use standard ActionBar)
I mean is: why we shouldn't do this...?
thanks... :)
ActionBar comes with a useful API, which allows you to add an app/menu icon to the left, and title, tabs, and action icons, as well as skinning options via themes, in a way that looks consistent across all your Activities and Fragments.
ActionBar also behaves (mostly) gracefully across different devices formats, keeping icon, title and action items in a uniform layout, while hiding excess action icons into a menu on the right. If you develop your custom implementation, you need to test that it doesn't break across Android versions and devices.

Toolbar as self-managed ActionBar vs Toolbar as framework managed ActionBar

Alright, I am trying to understand what I would lose if I use Toolbar as a self-managed ActionBar and not use setSupportActionBar.
AFAIK, all that ActionBar does is, provide placeholders for logo, navigation and menu items and also let Fragments add/customize the menu items.
The same functionality could be achieved using Toolbar.setLogo(), Toolbar.setNavigationIcon(), Toolbar.setNavigationOnClickListener() and Toolbar.inflateMenu() apis. Of course, directing the menu handling logic to Fragments might be lost but I think that is not that big of deal if the Activity knows which Fragment is on top and changes the menu items accordingly.
I am trying to make sure :
If I can achieve every ActionBar capability just by using Toolbar and MenuItems (and not using setSupportActionBar()).
Is it ok to not have an exhaustive knowledge of ActionBar apis. Some of the ActionBar apis are very confusing. Using setHomeAsUp api to show hamburger icon, back icon etc., doesn't feel right. If someone starts learning android today, do they even need to understand the framework's ActionBar apis?
Update : In the article Android Design Support Library under section CoordinatorLayout and the app bar, I learnt that the new paradigm app bar is a replacement for the action bar paradigm. I think action bar will soon be deprecated and we should get used to the new app bar paradigm which covers the new material design user experiences.
Yes you can use achieve similar capabilities of ActionBar in Toolbar.
Mainly the difference lies is Toolbar becomes part of View so we can much more fun playing with them to get Scrolling Techniques
You can use Toolbar separately as View & perform ActionBar alike functionalities. For example, in one of my app I use 2 Toolbar one which is set to setSupportActionBar() while other is just used for some other functionalities.
Conclusion: Well it depends upon your requirements if you want to use Toolbar as self or framework. None the less you can use it as both.
I hope this answers your question well.
To me you are right.
From AppCompatDelegate source code, method setSupportActionBar(),
When set to a non-null value the getSupportActionBar() method will return
an ActionBar object that can be used to control the given toolbar as if it were
a traditional window decor action bar. The toolbar's menu will be populated with the
Activity's options menu and the navigation button will be wired through the standard
android.R.id.home menu select action.
So these are most, if not all, the benefits you will have. As you said, it is easy to implement navigation and menu inflating through Toolbar APIs. However, I don't see what you would gain by not calling setSupportActionBar().
YES YES YES
using setSupportToolBar() is the same old Actionbar the only reason ToolBar is ToolBar is for versatility,same as Fragments is to Views, all lies on how you implement stuff, and also the old Actionbar is kinda boring and much restricted as to Toolbar

Android tab layout issue

I'm having a bit of a problem with the Android tab layout. I've been trying to make a screen that holds 4 tabs, and a fragment beneath them, when a user presses each tab the fragment dynamically switches to another activity and the tabs stay static, my problem is that I tried to implement it with tab layout and it's deprecated in since Android 4.0, so I tried it with the action bar tabs but then I have the action bar that I don't want nor need.
I have two questions:
Is it possible to use action bar but to hide the action bar and show only the tabs?
Is there a way to use tab layout on Android 4.0 and higher versions?
1.Yes there is possibility.....you should try http://actionbarsherlock.com/
2.ActionBarSherlock works from sdk 7 to sdk 16
I am not really sure about whether you can achieve it or not but if you want to play around with the ActionBar, this would be one of the best places to start.
Just because it is deprecated, doesn't mean that you can't use tabs in Android 4+. ;)
You surely can use Tabs and TabLayout in Android 4+ and everything works perfectly(though you apparently should not as ActionBar is a must better option).
I have tried it myself because even I prefer the TabLayout more than the ActionBar, and thankfully haven't run into any issues until now!
The only thing you will notice is that Eclipse will draw a yellow line over the deprecated code (which you can obviously ignore or just choose to hide all deprecated warnings).

ActionBarSherlock wrong tabs position on android 2.2.2

I'm having serious problems getting tabs in actionbarsherlock below main action bar tabs to work in an app that runs from Android 2.2 up and looks like Android 4. (see link)
Tabs position
Have you tried running the official Demos app of ActionBar Sherlock? (https://github.com/downloads/JakeWharton/ActionBarSherlock/ActionBarSherlock-Sample-Demos-4.2.0.apk) It should contain a demo for the actionbar with Tabs.
If that works on Android 2.2 then you know the problem is in your code and you can check the Demos source code to see what you are doing differently (https://github.com/JakeWharton/ActionBarSherlock/tree/master/samples).
It's usual behavior of action bar (actionbarsherlock just simulate it). Use
ActionBar act = getSupportActionBar();
act.setStackedBackgroundDrawable(getResources().getDrawable(R.drawable.mytab_base_t));
to avoid white color in top bar (this option you can't access from any theme item yet). You can also monitor action bar height to change custom view of tabs on-fly, but you can't change action bar behavior, forget it. Otherwise please use PagerTitleStrip against action bar tabs.

Which sub navigation pattern on a tabbed pageable ActionBar main navigation for Android?

Does anyone of you know of a sub navigation pattern in Android that uses a tabbed ActionBar navigation with pageable Fragments for its main navigation? (ViewPager)
I have looked at Spinners in the ActionBar which could work quite well if it wouldn't take ages to get the submenu rendered in the ActionBar while swiping from one tab to the next. (in the end you have jumping action items which look pretty ugly)
The other approach would include a segmented control widget which is known from the iOS platform. (like the TED application has it at the moment)
But what would be the Android way of doing it?
Why can't you try menu's for different tabs? I dont know whether it helps or not.Surf google for creating menus for each tab.

Categories

Resources