I want to build a tabbed interface, so I took the Tabs3 view from the API demos sample project, however for some reason the Holo theme is not being applied to my app It should look like this But it looks like this.
This is the relevant bit in my manifest:
<application
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:theme="#android:style/Theme.Holo.Light">
<activity android:name="Tabs"
android:label="#string/app_name" >
At this point all I have done is copy over the Tabs3 class (renamed to Tabs), List1, List8 and Controls1, along with the related layouts and strings.
Thanks for the help!
You use the wrong tabs. Here is a full tutorial how to use ActionBar.Tab. Click me!
Remind, ActionBar.Tab is only available on API Level 11 or higher, if you want to support Android API Level 10 (Android 2.3) or lower, you have to use ActionBarSherlock.
The Holo theme is only available in Android since API Level 15. If you want to use the Holo theme on lower API levels you should take a look at HoloEverywhere.
Holo Theme is available for API level 11 and up. That might be the reason for it not working. If anything you can use ActionBarSherlock for lower API levels.
Related
I'm going through the tutorial at developers.android.com and I had problems with styling the action bar. I use the newest SDK (the bundle with Eclipse).
Say, that in values-v14/styles.xml I have
<style name="MessageTheme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
I've tried all the variations of that that I could find. Tried without DarkActionBar in values-v11 as well.
It compiles fine but when I open activity styled as such, app crashes and logcat says
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
Like I said, API is set correctly. The target one in project properties (API 19) and android:minSdkVersion="14" in the manifest (tried higher as well).
Now, my activity extends ActionBarActivity (that's how the file was generated). If I make it extend Activity instead, then Holo works fine. That's an answer I found, but I don't understand why that works. What exactly is the difference between ActionBarActivity and Activity that makes this works and is this some hack or is it supposed to be done this way?
Also, that works fine with my additional Activity. If I try to this with the main activity from the tutorial, it doesn't compile because 2 methods used there are undefined - getSupportActionBar and getSupportFragmentManager.
You are using a compatibility library, so to style a support actionBar you need your theme to be descendant of appCompat.
Try this:
<style name="Theme.whatever" parent="#style/Theme.AppCompat.Light.DarkActionBar">
If you are still a little lost, you can generate your theme with this tool: ActionBar style generator and take a look how it's done.
Edit:
Check this out, also: Styling the Action Bar
See "For Android 2.1 and higher"
About the difference between Activity and ActionBarActivity...
As far as I know, you extend ActionBarActiviy if you need to have an action bar while targeting lower than 3.0 android versions. That's why you are having troubles with actionBar or supportActionBar depending on what kind of activity you are coding.
So, to summarize, when working with Acivity call actionBar, but If you are extending ActionBarActivity you should call SupportActionBar. For instance: getSupportActionBar().
More info you could use: Support Library Features
Edit 2: Android is yelling at you because your are trying to use appCompat features. To avoid this in your particular instance, all you need to do is NOT extending ActionBarActivity, but coding regular Activities. Then use ActionBar features as normally you would do.
Edit 3 and probably last:
Let's guess you are using holo as theme, and you are coding a regular Acitivty for API 11 and above. In this case you are not extending ActionBarActiviy, so you don't have to do anything special. That's ok, right? but now, you want the same thing to work for API versions lower than 11 and here comes your real problem. To make that happen you must extend ActionBarActivity, but you didn't. So your only way out (as far as I know) is to have another activity that extends ActionBarActivity, and somehow detect with code, which version of android is running, in order to execute the right code (this is, which class you of the two you should take advantage of) so your app would be able to avoid crashing.
Thats why I think using only appComapt is a nice solution, assuming you don't really need to use holo. But, if you truly want to make things that way...
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
// Use a regular Activity class for API 11 and above.
}
else{
// Use an activity extending ActionBarActivity. Have in mind that here you would be calling a supportActionBar instead of a regular ActionBar.
}
I just wanted to give my actionbarsherlock tabs another color. Therefore, I found this interesting article: Styling the Actionbarsherlock tabs
Now, my problem is that for me it only works for API level before 11. What am I doing wrong? I implemented the code from the solution just like that.
One other thing that I did, was increasing my API level (from 7 to 11) because this line from the code in the article
<item name="android:actionBarTabBarStyle">#style/Theme.app.tabbar.style</item>
produced this error:
android:actionBarTabBarStyle requires API level 11 (current min is 7)
Any ideas?
For just API 11+ you can create a folder in res called values-v11 and make a style file in there, then only those styles will be applied if the API is level 11 or greater.
I'm just new in android.. i just wanna ask how to create a actionbar ??.. without using a import com.markupartist.android.widget.Actionbar that comes from a project that I have been downloaded.. Thank you .. I'm using a 2.2 version
You'll get a ActionBar by default, if your app runs HC+ (and you use the holo theme). However, since the ActionBar got introduced with HC (API Level 11) you have to use ActionBarSherlock, if you want to use it on pre HC devices.
From the Android Developers guide:
Beginning with Android 3.0 (API level 11), the action bar is included
in all activities that use the Theme.Holo theme (or one of its
descendants), which is the default theme when either the
targetSdkVersion or minSdkVersion attribute is set to "11" or greater.
Thus you simply need to set
<uses-sdk android:minSdkVersion="11" />
or
<uses-sdk android:targetSdkVersion="11" />
in your AndroidManifest.xml. You can, of course, set either to higher than 11 as needed, but 11 is the minimum for automatically including the ActionBar.
If you want to use ActionBar in your project, then just download it from this link
Download Actionbar library project
Now import this project into your eclipse.
After that set it as library in your project.
Its done...
I have an app with 4 tabs and icon images for each tab. I am using TabActivity and TabHost.
setIndicator ("Example", getResources().getDrawable(R.drawable.tabicon));
The app works fine with API 8 and when I have the following in the manifest file :
but when I explicitly put the targetSdkVersion="16" in the manifest, the tab icons are not showing.
How can I preserve the Tab icons without changing a bunch of code? Is there a Tab icon code sample I can follow for API 16?
thanks a bunch !!
TabActivity and TabHost are deprecated in API 11.
Instead use the ActionBar with Tabs (Example here), for compatability with API versions lower than 11 use ActionBarSherlock.
Don't use old APIs anymore!
My new game app was originally designed for a targetSDK of 13. I've since bumped it up, but my default buttons have changed in appearance. Not on the emulator, but on my actual Galaxy S3 phone, running 4.0.4.
The old buttons were rectangular with a translucent background and white letters. The new buttons look the same, but have an opaque, dark gray background. It happens for any targetSDK greater than 13.
Any ideas why, and how I can fix it? I'm not applying any specific style to them.
It is happening because of googles new holo theme
The way to stop it from happening is to specifiy a theme in you manifest (right below the android:name and android:label attributes of your activity. Adding the following line will remove you
<application android:theme="#android:style/Theme">
This should remove the holo theme, if it doesn't you can play around with some other themes until you find one which works. This might help - http://developer.android.com/guide/topics/ui/themes.html