I have one tough question. I am now playing with design of the Android application and I have the problem with way how the tabs are displaying from some width of display. I use ActionBarSherlock library and ViewPager for tabs.
The problem is that I use yellow color for ActionBar, black for tabs and again yellow for tab indicators, but when I look at the application on wider screen or in landscape mode (I guess approximately from width 400dp) I can't see the indicators, because tabs are hiden in action bar and indicator has exactly the same color. Is there som way how to change color of tab indicators from some display width?
I have tried to do it by making of layout-sw400dp/layout.xml, new 9patche's and new styles, but I can't make it work this way and I think now that it is impossible to do it this way. Do you have any idea how to do this?
Thank you very much in advance.
UPDATE
I have solved it in the following way. I have created folders drawable-w400dp and drawable-land (for ancient phones). Only phones where it will probably be displayed in the wrog way are black berry like androids.
Have you tried using the Action bar style generator. I used this and my tabs have highlights in both orientations http://jgilfelt.github.com/android-actionbarstylegenerator/ it generates 9patches and XML for you
Related
Screenshots
Background
Graphical tabs started to appear in stock Android application around ICS. However, they are quite different from the traditional tabs (link). Moreover, I have found no related tutorials.
Differences with Traditional Tabs
Graphics instead of text, obviously.
No selection indicator at bottom.
The color of the contents (graphics) indicates the selection instead.
Suspicions
Are they just tabs with an icon but no text, combining together with a suitable theme?
If yes, how to theme the tabs to achieve such effects?
The main difference is that old style tabs were implemented using TabHost and TabWidgets. However, since the introduction of the Action Bar the tabs are implemented as action bar tabs.
You can read about styling the tabs in here.
Basically you can create your own indicator, as well as choose between icons, text etc.
How do i make a tab bar look like this:
Yes, this is the tab of contact app of android 4.2.2 on samsung galaxy s3.
This is what I have so far:
As you can see, the height of the tabs is a bit low so the indicator override the text. So I need to increase the tab bar height.
The problem is I can't increase the height of the tabs further. Because of new android policy that limit tabs height ( it is explained here: Change Actionbar height on Android JellyBean).
Then how did google do that? Is there any tutorial to make a custom tab bar, or is there a trick to by pass limit of tab bar height?
Thank you very much for reading my quesion.
i am learning actionbar and created an actionbar with tabs .the following image shows the view
!
requestWindowFeature(Window.FEATURE_ACTION_MODE_OVERLAY);
ActionBar ab=getActionBar();
ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ab.setBackgroundDrawable(new ColorDrawable(Color.MAGENTA));
ab.addTab(ab.newTab().setText("Popular").setTabListener(this));
ab.addTab(ab.newTab().setText("Latest").setTabListener(this));
ab.addTab(ab.newTab().setText("Nearby").setTabListener(this));
They following are my queries :
the tabs have shifted to a bar below the magenta color bar. is it due to space constraints of mobile.if a wish to add any item to this magenta bar with the tabs below how can add to it and then show the same pattern whether it is mobile or tablet.
i want to make this tabs bar transparent so that i can see the text move behind it.i have tried to set its drawable as per code above but it has only changed of top bar but not the tabs bar.
what is way to have a button on the magenta bar onclicking i have this screen shift to left and show another screen which has some links show up in a way that partly this current screen is also visible.i hope i am able to explain my point.
kindly clarify
Question 1: It's down to device space constraints. The first paragraph in the Android documentation for tabs in the action bar show that if there isn't room it will split the tabs to a separate bar.
http://developer.android.com/guide/topics/ui/actionbar.html#Tabs
Question 2: You need to set the drawable for the background and the stacked background of the action bar to your transparent drawable. (Edit: Links in Ye Lin Aung's comment show how to do that).
Question 3: It sounds like you are looking for a navigation drawer layout arrangement to me. The best place to start on this would be this link:
http://developer.android.com/training/implementing-navigation/nav-drawer.html
Edit: The pattern will work the same for both mobile and tablets (though you may want to have an xml for smaller screens that have a slightly thinner drawer sizes).
The android documentation in the link above states that the drawer width should be set in dp units and that the drawer height matches the parent view. The drawer width should be no more than 320dp so the user can always see a portion of the main content. This should allow most phones to view it in both portrait and landscape and still see some content.
I am creating an application with ActionBarSherlock and using ActionBar tabs. Below is how I am defining tabs:
actionBar.addTab(actionBar.newTab().setText("test").setTabListener(new TabListener<AccountsListFragment>(this, "accounts",AccountsListFragment.class)));
I am trying to change the height of the tabs. From what I understand there is no way to change just the height of the tabs. You also have to change the height of the main action bar(I am pulling my definition of the main action bar from)
http://developer.android.com/design/patterns/actionbar.html#considerations-split-action-bars
So how you change the height of the action bar is using the below style inside the main theme
<item name="actionBarSize">100dp</item>
<item name="android:actionBarSize">100dp</item>
The above code seems to work on all devices to change both the Main action bar and the tabs except jellybean. I tested this on a 4.1.2 galaxy nexus. Also on a 4.2 Nexus 7. It seems to work the same on both. It only changes the main action bar and not the tab height at all.
We also tried a custom view for the tabs which did not help us.
If anyone can point me to where in google it says that they do not allow changing height of tabs anymore(Which I doubt is the case) or give me a style to fix this issue. I would greatly appreciate it. If you even give me an example on a normal action bar and not sherlock that should help me.
To me it sounds like a silent bug fix. They make some of these at every new release. I doesn't make sense that changing the height of the actionbar should increase the size of the tabs and it isn't something that has been encouraged by Google, rather it's a hack developers have found nice to use. Your only other option is to make it yourself, but it's quite complex and could prove to be time consuming.
Similar post here:
Change Actionbar height on Android JellyBean
I've asked a similar question about the Android ActionBar before: Change ActionBar Tabs background color
I still don't have an answer to the question: when will the two line design/when the one line design used? I've set a custom divider to my tab bar and it's also being used in the horizontal layout. However to create drawables/styles based on the orientation/screen size etc I need to know when which layout is being used. Looking through the Android source it seems they are using the same drawables for both layouts, so that doesn't really help me. The same problem applies when changing the font color of the Tab View.
I fear that it'll be decided in code which format is being used, so there's not really any way around this. Can anyone confirm this? Or is there at least a way to find out in code if the Action bar is one lined or two lined?
Android will stack tabs beneath the action bar when it deems the screen size/orientation to be narrow (like on a normal sized screen in portrait, or on a small sized screen regardless of orientation). Similarly if there are many tabs, in some cases they will appear as a drop-down list in order to ensure the best fit in the action bar.
The Action bar is a highly adaptive UI control. If you are going to use its navigation modes I would strongly suggest not trying to anticipate their configuration or attempt to apply styles that are specific to each one. Your tab drawables will always need to be 9patch anyway because the base action bar height will also vary across orientations and screen sizes (notice its height is slightly smaller in landscape).
That said, you can query the action bar height at runtime using its getHeight() method. This Honeycomb Gallery example included in the SDK uses a bunch of logic in an OnGlobalLayoutListener to ensure that the Fragment layout responds to the various action bar sizes appropriately.