Holo Theme Backwards Compatibility for Action Bar tabs - android

I am currently working on an application using the Holo theme and am targeting the minSdkVersion = 9. I have an action bar with tabs throughout the entire application that work from version 11+ and am wondering the best way to use backwards compatibility to get versions 9 & 10 to function correctly.
Thanks!

You can use ActionBarSherlock. This will give you a backwards compatible ActionBar and ActionBar tabs.

Related

Split ActionBar

I want to have a split action bar for android where the search widget is at the top action bar and the rest of the icons are in the bottom using android:uiOptions="splitActionBarWhenNarrow" is there a way to do that?
Thank you.
splitActionBarWhenNarrow is not supported by Theme.Material or the appcompat-v7 action bar backport.
If you wish to stick with something based off of Theme.Holo for all devices, you are welcome to use splitActionBarWhenNarrow.
If you wish to use either Theme.Material or appcompat-v7, you will need to create your own "split action bar", by having a Toolbar at the bottom of the screen that you populate separately.
For example, this sample project uses a Toolbar on API Level 21+ devices along with Theme.Material, gracefully degrading to having everything be in the action bar on Android 4.x devices.

Logo not showing in Theme.AppCompat.Light.DarkActionBar style [duplicate]

I followed up the instructions of building a new android project and I got a runnable one except a problem with action bar. The problem is that the application icon is not showed beside the application title on action bar. I created the project with the configuration below:
Minimum required SDK:API 8: Android 2.2(Froyo)
Target SDK:API 21:Android 4.X(L preview)
Compile With:API 21:Android 4.X(L preview)
Theme:Holo Light with Dark Action Bar(Eclipse set the corresponding appcompat theme)
Android Support Library 21.0.1
Android SDK Build-tools 21.1.1
Because my minimum sdk is api 8 which does not support action bar, so the project includes a appcompat_v7 library to allow the action bar feature. If I set the minimum sdk to api 14(android 4.0) or higher, then the project does not include appcompat_v7 library and application icon is showed successfully also. But I need my app to support older android os as low as api 8. So what should I do to fix this problem? Really appreciate you guys attention.
P.S: I went through the task above on windows ,mac, eclipse , android studio and got the same result.
You are using the AppCompat version 21+ and it is normal.
The Action Bar follows the material design guidelines and uses a Toolbar.
As you can read here:
The use of application icon plus title as a standard layout is
discouraged on API 21 devices and newer.
If you would like an application icon (but I discourage it), you can use the method setLogo().
Something like this:
ActionBar actionBar = getSupportActionBar();
actionBar.setLogo(R.drawable.my_logo);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
This issue comes when you use support library revised 21.
Use:
ActionBar actionBar = getSupportActionBar();
actionBar.setLogo(R.drawable.ic_launcher);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
It worked for me or you can use toolbar. A Toolbar is a generalization of action bars for use within application layouts.
In modern Android UIs developers should lean more on a visually distinct color scheme for toolbars than on their application icon. The use of application icon plus title as a standard layout is discouraged on API 21 devices and newer.
Reference: https://developer.android.com/reference/android/support/v7/widget/Toolbar.html
Make sure you have the icon set in the manifest.xml file, in the application tag as:
android:icon="#drawable/launcher_icon"
Then in the onCreate method insert the following lines:
ActionBar ab =getSupportActionBar();
ab.setDisplayShowHomeEnabled(true);
ab.setIcon(R.drawable.launcher_icon);
This is a common "problem".Before you pull your hairs out make sure you are using:
import android.support.v7.app.ActionBar; //or the v4, haven't tried with that though
and not:
import android.app.ActionBar;
and then:
ActionBar actionBar;
actionBar = getSupportActionBar();
instead of:
actionBar = getActionBar();
And finally:
if (actionBar != null) {
// enabling action bar app icon and behaving it as toggle button
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setIcon(R.drawable.your_icon);
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}
Attribute logo is only used in API level 11 and higher (current min is 8), I was also confused about this question, maybe google just don't want the icon to show on material design, when the minimum sdk is set to 14 or higher and under 21,it uses holo theme, it has an icon, but appcompat style is more like material design I think, maybe google just forget to modify the holo theme
IN Style.xml
<style name="MyTheme_ActionBar" parent="#style/Theme.AppCompat.Light">
<item name="icon">#drawable/actionbar_logo</item>
</style>
In activity add this and try
ActionBar mActionBar = getSupportActionBar();
mActionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP |
ActionBar.DISPLAY_SHOW_CUSTOM |
ActionBar.DISPLAY_SHOW_HOME);

Cannot set split ActionBar using support libraries

I have searched a lot on the internet but I still can't set split action bar. I also attempted official documentation's methods but nothing works.
I'm building app with minSdkVersion = 9 and targetSdkVersion = 21 and using AppCompat Theme I successfully changed the color of actionbar and text but cannot add split ActionBar.
I added uiOptions = "splitActionBarWhenNarrow" in manifest file and also added meta-data for backward support but split action bar is still not visible on either narrow or wide screens.
appcompat-v7 as of version 21 no longer supports the split action bar, as Android 5.0 no longer supports the split action bar.
If you want that sort of thing, you have to do it yourself, via a Toolbar or something that you position at the bottom of the screen.

How to to hide action bar (Theme.Holo) if Android version below 3.0

I notice the action bar (Theme.Holo) looks cool only in android 3.0 or heigher, but it doesn't like nice on for example Android 2.3.
is there away to show the action bar ( Theme.Holo) based on Android version?
The action bar requires API 11 minimum. If you want to remove it programatically though you can use hide() in the code for that activity.
ActionBar actionBar = getActionBar();
actionBar.hide();
Not really sure what it would show for anything below 3.0, but it seems like the best place to start.
Edit:
You can check the SDK version at run time with the Build constants
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { //checks if its lower than Honeycomb
ActionBar actionBar = getActionBar();
actionBar.hide();
}
That is because the ActionBar wasn't added until Android 3.0 (API level 11) so any version of Android lower than that will have a title bar, not an action bar.
The ActionBar is not yet a part of the official compatibility library, so in the mean time, the ActionBarSherlock library will allow you to have an ActionBar that looks the same across all API versions.
If you want to hide the ActionBar completely just add adding android:style/Theme.Holo.NoActionBar to the activities in the manifest.

Honeycomb Action Bar not showing (baffled)

I am completely baffled. I created an application with minSDK=4 and targetSDK=11. Compiled and ran on the Xoom tablet. I am not getting an Action Bar and cannot figure out what I have done wrong. I have been staring at the screen for hours and don't know what I have done that would have caused the bar to disappear. Help! Any suggestions on why I am not seeing the Action Bar?
You need to declare android:theme="#android:style/Theme.Holo" for Activity in Manifest xml.
The dev guide says like you only need to set the target SDK version, but it does not work.
I'm quoting from here:
"If you are using the Support Library APIs for the action bar, then you must use (or override) the Theme.AppCompat family of styles (rather than the Theme.Holo family, available in API level 11 and higher)."
I used android:theme="#style/Theme.AppCompat" in my manifest and the action bar appeared.
Romulus' answer, forcing the App to use the Holo theme will work but it results in a compile error if your minSDK is less than 11.
Check if you have defined a theme in the AndroidManifest:
android:theme="#style/XXXXXXXXXXXXXXXXX"
That means you're forcing the App to use a particular theme, so the action bar might not appear on Honeycomb or higher devices (it depends if the theme specifies an action bar). Delete this statement to cause the App to use the default device theme, so the Settings menu appears on pre-Honeycomb devices and the action bar appears on post-Honeycomb devices. Job done. Hope this helps.

Categories

Resources