Stacked ActionBar tab bar not filling parent - android

I'm creating Action Bar navigation tabs, but when the Action Bar is stacked the tabs are not getting the whole width space. I have a foto to illustrate it.
Is possible, in this case, giving to each tab 50% of the screen width?
Thank you
I'm editing to say that it's not a Sherlock Action Bar. And I'm working in a Samsung Galaxy Note 10.1 and in a Nexus 7. And now, testing it in the Nexus, I noticed that it's behaviour is different. Another screenshot:

I don't think that's feasible at the moment. I've been trying to do the same thing for the past few days, and here's what I have found so far.
The Android framework uses a class called ActionBarPolicy to set some rules regarding the ActionBar's behavior.
In this file (which can be found here : https://github.com/android/platform_frameworks_base/blob/master/core/java/com/android/internal/view/ActionBarPolicy.java), you'll find a method called getStackedTabMaxWidth() which returns a dimen value (currently set in the ressources at 160dip).
This value is used is the inner class TabView placed in ScrollingTabContainerView (https://github.com/android/platform_frameworks_base/blob/master/core/java/com/android/internal/widget/ScrollingTabContainerView.java). TabView is the private implementation of the ActionBar's TabBar.
Now I don't think this value nor this behavior can be modified, except maybe using Reflection. I don't know enough about it to do so, so if someone could manage such a thing, don't hesitate to say so, because this really is a bad behavior which doesn't look great on some tablets.

Android stacked action bar tabs do not have adjustable widths.
"Stacked action bar tabs now have a width limit. This prevents super-wide tabs that can span the whole screen. The cluster of tabs is centered if it does not span the full width. " https://android.googlesource.com/platform/frameworks/base/+/b8139af3dcae80c0030afd0354dc424a7c72c3d9
The solution is to use the TabLayout API from the Android Design Support Library released with Android 5.0. The Android Support library requires the appcompat library, but that dependency is resolved for you if you build using gradle.
For most developers, this will not be an issue, but the TabLayout setup requries at least SDK API level 22, because the appcompat dependency is compiled against 22. However, TabLayout does not have a runtime dependency on 22, meaning you can run it on devices up to API level 7.
tl;r - Use Tablayout from Android Design Library. Requires API level 22 on developer, but can run on older phones up to v7.

Related

Android: What's the difference between a title bar and an ActionBar

I can't tell if they're the same thing or not and they seem to have different methods for removing them but I'm not sure if those are just multiple methods to do the same thing or not.
So is there a difference and if there is what is it?
Ref:
https://developer.android.com/reference/android/R.id.html#title
https://developer.android.com/reference/android/app/ActionBar.html (with material design, it is usually represented by a Toolbar)
The Title bar is a small part of the UI that you can supply with some text and a color. You see it on a lot of Android 2.0 Apps. See here
The Actionbar is the bar with buttons that has back navigation etc. If you can chose, you use it instead of the Titlebar. See here
Different thing.
TitleBar - small (usually grey) strip at top of screen that lists your Application Name (mostly not used anywhere)
ActionBar - the core navigation component of modern Android apps - this is where you will put the main navigation components (including actions on the things in your activity, a title explaining where you are in the app, Share links, etc); To support this in all modern Android versions, you will need to use a library to implement this. ActionBarSherlock is a very popular one, and there is now ActionBarCompat, which was released in the latest Support Library.
Bottom line, TitleBar should be disabled in favor of ActionBar for applications targeting modern design standards

Android - Action bar at top and tabs at bottom of the page

I am a novice Android developer. I have just started learning Android programming. I want to know whether it is possible to add Action Bar with Action Icons at top of the page and Tabs at bottom of the page! If so someone please guide me how to implement a code for it!
Thanks in advance,
UDAY
AFAIK, you can add action buttons on the bottom, only if there is no room at the top, however to do this, you should activate "split" option of your action bar in activity:
To enable split action bar when using the support library, you must do two things:
Add uiOptions="splitActionBarWhenNarrow" to each <activity> element or to the element. This attribute is understood only by API level 14 and higher (it is ignored by older versions).
To support older versions, add a <meta-data> element as a child of each element that declares the same value for "android.support.UI_OPTIONS"
This is quote from official docs, I recommend you to read more on http://developer.android.com/guide/topics/ui/actionbar.html
By the way, if you want to support older versions of android sdk (less than 3) use ActionBarSherlock it is third-party lib, but it has very similar ip to official actionbar and supports any version of android sdk. To learn more about it visit actionBarSherlock Home Page
To answer your question: Yes
Read android documentation about Actionbars
http://developer.android.com/guide/topics/ui/actionbar.html
And you see there is something called Bottom bars.
They should not be used for navigation tho as you can read on at
http://developer.android.com/design/patterns/pure-android.html

Action Bar in API Level > 3.0 but Still Support API < 3.0

Yet another compatibility question.
THE PROBLEM
I need to use a tabbed action bar in api level 3.0 and greater to switch between fragments. However, I also need to be able to switch between these fragments somehow in api level < 3.0.
The spanner in the works is the fact that I have already downloaded a custom compatibility library that allows me to use google maps with fragments and therefore I can't use a library.
THE QUESTION
How can I implement a tabbed ActionBar solution in 3.0 and greater and also cater for the bigger market that is 3.0 and less?
Any help would be grand.
What you want is ActionBarSherlock. It uses the native action bar for API >= 3 and provides backwards compatibility for API levels 2.x. There's also the Action Bar Compatibility sample project (listed as SupportAppNavigation, I believe). I think this is essentially the same thing.
So I managed to figure a solution a while ago, it's just taken me a while to post it here.
This is the solution that works for me. I needed to use an ActionBar but I also needed to use the MapActivity as well as the FragmentActivity hence not being able to use ActionBarSherlock.
What I did was the following:
Created a fragment called CCActionBar which handles the touching of the CCTab's by adding itself as a listener(explained below). It also inflates a layout called action barlayout which has the tabs and images arranged, just reference the tabs at run time.
Created a custom view called CCTab which represent the tabs of the action bar. When its touched it tells its listener (CCActionBar) its been touched.
In my main layout xml file have an action bar container which I show or hide at runtime depending on the API level.
Now in my main activity in my OnCreate method I check whether my API level is greater than 3.0 or not. If it is I just implement the standard ActionBar making sure my custom action bar container is invisible. If it isn't I set up my custom action bar and make sure my action bar container in my xml layout is visible.
Then I make sure that when a tab is pressed whilst using either method it is handled in the same way so once its setup you don't have to handle it any differently.
I hope this helps someone somewhere or at least give you an idea of how to proceed.
What I would recommend is to use ActionBarSherlock to get the tabbed action bar functionality.
I assume that you also need a MapView support in Fragment. For this I would recommend solution from MapView in a Fragment (Honeycomb)
(look at user1414726 answer with sample code).
I think it is a better solution than using library though it is using deprecated LocalActivityManger. But in my opinion it is a better idea than using library where every Activity is a subclass of MapViewActivity which I assume you are using.

Action Bar Sherlock like UItoolbar dark

I found this library and liked it. Know i am searching info how to use it. I am creating app which support from SDK 2.1 to 4.*.
So i downloaded ActionBarSherlock version 4.0. Imported library and made dependence to that library. I was needed to use Api level 15, because it is requirement for library usage.
So i imported project Demo from samples.
Everything look fine, but i really don't like this:
[2012-03-29 11:18:46 - SampleList] Displaying it with 'Locale Language ___Region __, sw320dp, w320dp, h533dp, Normal Screen, Long screen aspect ratio, Portrait Orientation, Normal, Day time, High Density, Finger-based touchscreen, Soft keyboard, No keyboard, Exposed navigation, Trackball navigation, Screen resolution 800x480' which is compatible, but will actually be displayed with another more specific version of the layout.
However i need this library creating navigation bar on top of all my layouts and change buttons action up to which layout i am.
So my target is to do this NavigationBar:
Maybe someone have done this with ActionBarsherlock and could help me ?
Also is it possible with ActionbarSherlock to do on Top Navigation Bar and on buttom Tab Bar with images ?
it should look similar:
Thanks
The library was designed to mimic the Ice Cream Sandwich action bar which has fundamental differences in both design and interaction patterns. I'm fairly certain that you could bastardize ActionBarSherlock into looking somewhat like UIToolbar, but it would be far easier to just create custom views to do this for you.
Also, please do not do this. Not a single Android user on the planet will thank you an iOS interface on an Android device.
http://developer.android.com/design/index.html

Custom Title bar & Tabs

Is there any way to change the content of the title bar when it's in Tab(If it wasn't in tab I would have done it but tried couldn't find any solution). E.g. Suppose I have created a custom title bar with few buttons on it, and now I want to change the content of the title bar(Drawables, Title and the functionality).
It would be great if someone could tell me if i can implement Action bar in versions below 3.0 ? I am creating this project in 2.1 (I'd like to create action bar from scratch).
or if there's any way beside inserting an image and placing buttons on it(This methodology would be good enough)?
If you're just looking to implement the ActionBar paradigm in pre-Honeycomb versions of Android, I suggest you look into using the ActionBarSherlock library.
The library will automatically use the native action bar when
available or will automatically wrap a custom implementation around
your layouts. This allows you to easily develop an application with an
action bar for every version of Android back through 1.6.
twaddington and pjco's answers are correct, you need to use ActionBarSherlock if you want to be compatible with every SDK levels.
I want to add you can have a custom actionbar or a custom view for your actionbar tabs using the method actionbar.setCustomView(view) or tab.setCustomView(view)
Anyway, play with ActionBarSherlock demos, there are a few cool use cases.
The other option worth looking at is ActionBarCompat, which I think comes with the SDK 14 api demos. However, ActionBarSherlock seems to support many more features so that may be the better solution.

Categories

Resources