HoloEverywhere seems to work without extending Sherlock classes. Why do I have to change the imports?
I've just added: android:theme="#style/Holo.Theme.Sherlock"
in the manifest tag and the theme seems to work on the emulator (Android 2.2).
Instructions say:
Extend the Activities from com.WazaBe.HoloEverywhere.sherlock.S***Activity
My Question
Is it a must or an alternative way of applying Holo theme individually?
Does extending the activity from com.WazaBe.HoloEverywhere.sherlock.S***Activity also add ActionbarSherlock to the Activity?
Thanks!
If you want a complete Holo theme port to pre-honeycomb devices, you must extend these classes. If not, some simple controls like EditText or similars will be displayed with holo theme, but others more complex like Dialogs will not be holo-styled.
Related
I have seen similar questions asked with solutions which solve my problem but I was wondering if anyone can explain it to me.
I am following instructions on the Google Developer website to apply the Material Design Theme located here. However, I am getting an IllegalStateException when I try to run the app on the emulator. My theme inherits from parent="android:Theme.Material" as specified in the instructions provided by Google.
The issue is solved by using Theme.AppCompat. Why is it that the instructions that Google provide leads to an error? I read that Theme.AppCompat extends Theme.Material, I don't know if that is true. Why can't Theme.Material cannot be used?
I tried following the line of extension for Theme.AppCompat but I didn't see it inherit from Theme.Material anywhere.
Why is it that the instructions that Google provide leads to an error?
The instructions assume that you are using Activity, not AppCompatActivity, as your base class for your activities. In your case, you are using AppCompatActivity.
I read that Theme.AppCompat extends Theme.Material, I don't know if that is true.
It is not true.
On Android 5.0+ devices, Theme.AppCompat will extend Theme.Material, indirectly. On older devices, it will not, as Theme.Material did not exist. Your error is coming from AppCompatActivity, which validates that you are using a theme that is based on Theme.AppCompat and therefore does not accept Theme.Material.
Probably you have one (or all) of two these problems:
1) You use only 1 xml file style.xml, where your wrote something like:
<style name="AppTheme" parent="Theme.Material">
And then you run app for device with api lower than 21.
Then you have problem, that devices with api < 21 don't know about your Material theme.
2) You use Material theme for api>=21 and AppCompat for api < 21, but your Activity extends AppCompatActivity, then you have a problem. Because AppCompatActivity requires AppCompat theme, not material
Please, have a look to this answer for more details
Also from official documentation page about AppCompatActivity:
Base class for activities that use the support library action bar features.
You can add an ActionBar to your activity when running on API level 7 or higher by extending this class for your activity and setting the activity theme to Theme.AppCompat or a similar theme.
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.
}
For some Activity I'm using #Theme/Dialog, but this appears like old UI 2.3.
If I set the Theme of the Activity in the Manifest as Holo/Dialog, then this work fine, but of course this will not work with older devices.
How to force Holo Theme when available?
I tried with a custom MyTheme, but all the activity that have #android:style/Theme.Dialog, continue to appear like old theme.
My activity look like below:
<activity
android:name=".audio.TempoManager"
android:label="Tempo Manager"
android:theme="#android:style/Theme.Dialog" />
if I change it to #android:style/Theme.Holo.Dialog then on old device the activities will not be open as dialog but as simple activity.
refer to this blog post. it answers your question: holo-everywhere
mainly:
1. you write a theme.xml file defining a MyTheme in res/values/ for all pre-3.0 android versions.
2. write a themes.xml file defining the MyTheme in res/values-v11/ for 3.0+ android versions.
3. in the AndroidManifest.xml define the application theme to be MyTheme.
the first theme inherits from #android:style/Theme.
the second theme inherits from #android:style/Theme.Holo.
If ICS is available on the device it will default to Holo,
If you want to create for instance the ICS font universally on all devices you will need to provide the ttf font file asset and use it in a custom textview and/or buttons etc..
I am writing my little Android app. I pop up a dialog control which is a nice, non-fullscreen, rounded-corners dialog by setting android:theme="#android:style/Theme.Dialog" on the activity in my manifest. That all works just as I expected. However it is just a drab, grey-titled dialog as in this screenshot:
I've noticed however that a LOT of applications, when they pop up dialogs have a nice, blue-themed title as in this screen shot.
I would assume this theme is some common theme, as it shows up in a LOT of different apps. I would assume it is something built in to the OS. (My phone is a Captivate with the official Froyo release). Of course it COULD be something that every developer simply re-coded on their own, but I doubt that.
Assuming that this is a common theme, how do I utilize it in my app? What changes do I need to make to my activity to have it use that theme?
Thanks in advance!
You can set your activity to use a default theme like Theme.Black. There are default themes and they are in R.style - although i'm not sure which are available to which platforms(i.e. i think the holo themes are for 3.0 and up...
http://developer.android.com/reference/android/R.style.html
see here http://developer.android.com/guide/topics/ui/themes.html for defining your own custom themes and scroll all the way down for using the "platform styles" and themes.
Rather messy (there doesn't seem to be a good reference for this), but the platform styles are defined in \platforms\android-\data\res\values\styles.xml and \platforms\android-\data\res\values\themes.xml. You can dig through those and figure out the theme/style IDs that are available at compile time.
Other than that its really just trial and error.
To make a dialog you need to extend the dialog class. And to have a nice title bar you can use:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
and have your own custom title.
to have a title use:
setTitle("MyTitle");
You can also assign your custom view for the title.
Did anyone implemented multi theme support for android app? Are there any common practices for this?
Thanks for any advice.
UPD: The main problem for now is that android's theme engine doesn't support selectors like in CSS. For example if I have two views with "background" attribute there's no way to make theme engine distinguish those ones and set different backgrounds. I can specify different style for each view but this approach lacks flexibility 'cause it's impossible to apply style for whole activity at once.
As far as I know, there is no way to set a theme to the whole application in on line of code. If you want to change the theme of an activity, you need call setTheme() in its onCreate() method, BEFORE calling setContentView. So to make it easier for you, you could do a switch on all your themes, and select one in regards of what the user has selected. Now, if you want it to apply easily to all your activities, you could make all your activities be a subclass of a custom Activity in which you would only set the theme. Activity <-- ThemeActivity <-- all your Activities