I am trying to implement an action bar with tabs as navigation options. To do that I select the "Tabs+Swipe" option in the "New Blank Activity" section of the "New Android App" wizard as shown below.
Now, in the android manifest, when
android:targetSdkVersion="15"
which is the default value, the action bar looks like this on a Nexus 7/Nexus 7 emulator, this is the desired look of the app
Now when I change that line in the android manifest to
android:targetSdkVersion="16"
the look of the action bar changes to this
The default look remains for any version of android but 16, can anyone please explain why the look of the action bar suddenly changes when the targetSdkVersion is set to 16?
The above is reproducible in the emulator as as well as on a real nexus 7.
Full screengrabs for
Normal: http://i.stack.imgur.com/VsBA2.png
After android:targetSdkVersion="16": http://i.stack.imgur.com/OM6Y4.png
Update-10th March, 2013: Switched to the List Navigation mode (instead of Tabs) to enable move to android:targetSdkVersion=17
The reason it changes when setting targetSDK to 16 is because Google changed how tabs are measured in Jelly Bean. Specifically, look at this in android.internal.view.ActionBarPolicy:
public boolean hasEmbeddedTabs() {
final int targetSdk = mContext.getApplicationInfo().targetSdkVersion;
if (targetSdk >= Build.VERSION_CODES.JELLY_BEAN) {
return mContext.getResources().getBoolean(R.bool.action_bar_embed_tabs);
}
// The embedded tabs policy changed in Jellybean; give older apps the old policy
// so they get what they expect.
return mContext.getResources().getBoolean(R.bool.action_bar_embed_tabs_pre_jb);
}
However, I suspect you don't just want the reason, but a solution. Unfortunately, I can't give you a straightforward way to set it to only embedded.
I can suggest using ActionBarSherlock to make it consistent, though. The bonus to that is the ability to use actionbars on older devices. When using it(portrait), I can confirm that if you set the targetSDK to 16, it uses the stacked layout on Jelly Bean, Ice Cream Sandwich, GingerBread, and Froyo. At least you will be able to design your layout while knowing what to expect.
Keep in mind that in most cases, switching to landscape mode will embed them in the actionbar again, since there is "enough room" the way it measures.
Related
I try what simon tell to do for change direction but it's doesn't working.
It's seems that for hundredth of a second it's work but when Action bar add the action buttons it's put the buttons at left instead at right.
What can be the problem? it's seems that somewhere in nmy code had line that tell freamwork to do otherwise?
The RTL value (true or false) is included in the flags in getApplicationInfo.flags.
As a long shot - is it possible that you are somehow changing the value?
The ability to set RTL was added in Android 4.2 if you are supporting this OS level or higher, this will be easier for you to accomplish.
Proof it is 4.2+: https://groups.google.com/forum/#!topic/actionbarsherlock/-npidM2Eo0w
Google post outlining how to change to RTL: https://plus.google.com/+AndroidDevelopers/posts/HuHNSb8V7s8
Otherwise, I would reference the SO question already pointed to in another comment if you are supporting an OS level older than 4.2: How to handle RTL languages on pre 4.2 versions of Android?
I just deployed an ActionBarSherlock app to a 2.3.6 device, but the main action bar does not show. I tested the contextual action bar on a ListView item, and it works correctly. I am using Theme.Sherlock.Light for my theme. Any idea what could be causing this problem?
Additional Information:
Samsung Galaxy Ace
LDPI - 480 x 320
Targeting API Level 18
Min API Level 10
Edit 1:
I wanted to add this in case it may be related, maps v2 also doesn't load correctly on the Galaxy Ace.
This was a stupid mistake on my part. I was extending OrmLiteBaseActivity and not SherlockActivity. In case someone using OrmLite happens upon this question, you can get the helper by calling (DatabaseHelper) OpenHelperManager.getHelper(this, DatabaseHelper.class) instead of using getHelper.
i have been looking at several examples with the action bar/menu bars. but my tablet is different, at the bottom there is the back button, home, recent, three dots.....
i cannot use menu bar at the top since my app is full screen surface view that refreshes over it
i cant figure out which code is for the three dots....at the bottom left corner
http://cdn.liliputing.com/wp-content/uploads/2012/06/apps.jpg
can someone point it out pls?
The button you are seeing is the legacy menu button. It is shown for apps targeting API versions 10 and below. Specifically:
If you set either minSdkVersion or targetSdkVersion to 11 or higher,
the system will not add the legacy overflow button.
Otherwise, the system will add the legacy overflow button when running
on Android 3.0 or higher.
The only exception is that if you set minSdkVersion to 10 or lower,
set targetSdkVersion to 11, 12, or 13, and you do not use ActionBar,
the system will add the legacy overflow button when running your app
on a handset with Android 4.0 or higher.
For more information, read Say Goodbye to the Menu Button.
Without some sample code, there isn't much more we can do to help diagnose your problem.
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.
I concluded the newer android tablets doesn't have a hardware Menubutton anymore.
So I was wondering if I have to insert an menu button in my own (fullscreen) app or does android offer a software included menubutton itself (even when my app runs fullscreen)?
(I don't have an android phone/tab myself to test, so I asked here)
Thanks,
Dennis
You should move away from menu buttons. It's the new style of Android applications. See this post from Android developer with the reasons to remove the button and what applications should do instead of offering a menu button.
Most of devices which are not having menu hardware button runs on android 3.0 or greater version
You just need to add one parameter as showAsAction.
Which will show menu item on action bar.
Concider reading ActionBar tutorial
Change the manifest file: you should change targetSdkVersion to <= 10.
Like this:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="9"/>