I have a couple of app that were created with Android 1.6 and after. The problem is when I run these app on recent Android (device or simulator) like ICS, I don't have the Holo theme.
I know i can find a lot of thread on how to specify the theme but when I create a new app now, I have the new theme without any lines of code.
I don't want to have ICS theme on all android version, just ICS theme on ICS, like new holo buttons style on ICS and old grey style for older. Now I just have grey buttons for all versions.
I can create new empty projects and copy all my files into it but there must be a hidden value somewhere to chenge this.
In my manifest I have:
<uses-sdk android:minSdkVersion="3" />
<uses-sdk android:targetSdkVersion="14" />
What can be the difference between old and new created projects ?
What I'm understanding is that you want your app to switch between the legacy (classic) theme and the new Holo theme based on API version.
First, in your values (res/values) folder make a new xml. Call it styles.xml. It should contain these lines:
<resources>
<style name="AppTheme" parent="#android:style/Theme.Black"/>
</resources>
Then make a new folder in res called values-v11. In this new folder make another new xml. Also name it styles.xml This file should contain these lines:
<resources>
<style name="AppTheme" parent="#android:style/Theme.Holo"/>
</resources>
Then in your AndroidManifest.xml you Application node should contain this line:
android:theme="#style/AppTheme"
Now on devices with Honeycomb or higher you get the Holo theme and for everything else, you get the old classic theme. You can easily experiment with this to suit your needs - this is the general way to switch between themes based on API version.
Related
I am making a dialog, where I want to show EditTexts and Radio buttons.
But the theme is not applying. According to Layout Inspector, the Views have the correct theme applied (shown "forced"), but there is "android:style/Theme.DeviceDefault()", which is also "forced" (it is shown above my style, if that matters).
The problem is, that the Views look differently on different APIs, which I guess is caused by that DeviceDefault. I have not set anywhere anything about DeviceDefault, but it applies to all my Dialogs.
Any idea how to dissmiss it? Thanks.
Every API level has its own default theme and since you use the default theme to your app, android adjusts the theme depending on the API level which will be different on each device. Just remember that just the element of which you add the style attribute to gets the specified style attributes. The child objects or child view does not get the style attribute. If you want child views to inherit styles, instead apply the style with the android:theme attribute.
The problem is probolby linked to where, and how, you apply your own theme.
You should apply your theme in the AndroidManifest.xml file. If you apply your theme in the application tag or the activity tag, you cover different parts of the application with your theme. What you have done is hard to say without any code present.
You should apply your theme to one of the following sections of the file.
To cover the whole application
<manifest ... >
<application android:theme="#style/Theme.AppCompat" ... >
</application>
</manifest>
To cover just one activity
<manifest ... >
<application ... >
<activity android:theme="#style/Theme.AppCompat.Light" ... >
</activity>
</application>
</manifest>
If a view supports only some of the attributes that you declared in the style that you created, it then only applies those attributes and ignores the ones it does not support.
If you want to change the default style and colors, you can override them in the styles.xml file. Search for the item name that represents the color value and change corresponding value in the res/values/colors.xml file.
I hope this information will solv your problem, but as I said, it this really hard so exactly say without the code present.
About Theme.DeviceDefaul in Android:
There are many Themes available for Android devices.
Theme: the default for the earliest versions of Android up to 2.3 Gingerbread(10)
Theme.Holo: from Android 3.0 Honeycomb (11)
Theme.Material: from Android 5.0 Lollipop (21)
Theme.DeviceDefault: from Android 4.0 Ice Cream Sandwich (14), a theme that can be customized by the device manufacturer. It represents the native look of the device.
Specifying different themes:
Android's resource overlay system allows to specify styles based on device API level, via Android Studio will setup for you.
For example different versions of a style in res/values-v11 and res/values-v21.
/res/values/styles.xml is applied to every device and serves as base:
<resources>
<style name="AppTheme" parent="android:Theme.Light"/>
</resources>
/res/values-v11/styles.xml is loaded on all devices that have API level 11 and above (including those that are 21 and above):
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light"/>
</resources>
/res/values-v21/styles.xml is loaded on all devices that have API level 21 and above:
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light"/>
</resources>
AndroidManifest.xml is the place where the custom theme is put to use.
<application
android:theme="#style/AppTheme"
...
I would like to deploy my app on APIs 8-17. However, for purely aesthetic reasons I would like to apply the default theme as it appears on api 8 as the theme for the app across all API levels.
For example, the older theme has an edittext that has an orangeish border around it, whereas the newer them uses a borderless blue line.
By limiting which APIs i deploy too I have been able to accomplish this but that isn't really a solution.
Does anyone know how this can be accomplished?
Thanks
Update
For whatever reason applying "Theme" as the theme did not force it to revert to the "Theme" theme, but instead left it as the default Holo. Using the answers below I simply called "Theme" as the parent in my custom theme (without altering any of its attributes) and set it as my application theme in the manifest. This solved it.
In your res/values directory, you can have a themes.xml file with:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme" parent="#android:Theme">
</style>
</resources>
Your app theme will now subclass from default Theme instead of Theme.Holo and you should be able to get older theme on newer android versions as well.
If you're using the default theme, it will be different between the API levels. However in the styles, you can create a custom Theme, modify an existing Theme or give a different Theme to each different API of your choice.
I'm using the HoloEverywhere library in my Android app to ensure a consistent theme across all supported devices. However, I'm running into trouble with activities that utilize Holo.Theme.Dialog: on my Android 2.2 emulator it displays correctly, but on my Android 4 device (which has the actual Holo theme available) the layout cuts off items on the right edge of the dialog.
My question is, how can I force devices that have the stock Holo theme to use that instead of HoleEverywhere? Or, how can I modify HoloEverywhere to make activities styled as dialogs display correctly on Android 4+ devices?
Screenshots:
Dialog in Android 4+
Dialog in Android 2.2
I'm not sure if this bug has been fixed in HoloEverywhere or not, but my solution was to change all of my dialog activity classes to AlertDialogs. This required some code changes, but now I can be sure my dialogs will look and act as expected.
Here's what you need to do:
In your values folder, create a style in styles.xml file referencing Holo.Theme as a parent. In my case, I used AppBaseTheme
<style name="AppBaseTheme" parent="Holo.Theme.Light"></style>
In your manifest, make sure that you are referencing this style in your activities and in your application tag.
<application
...
android:theme="#style/AppBaseTheme" >
Create a folder in your res folder named values-11 (if there isn't one already)
Create another styles.xml file.
Copy the same style you placed earlier in values folder, but reference the built in Holo theme included in 4.0
<style name="AppBaseTheme" parent="android:Theme.Holo.Light"></style>
my problem is an Android app, that uses android:Theme as a default style and android:Theme.Holo.Light for OSes of version 11 and newer and android:Theme.Holo.Light.DarkActionBar for v14 and newer.
The app project was created using the ADT Eclipse-wizzard, so the AndroidManifest.xml sets android:theme="#style/AppTheme", and there are three styles.xml files, one in the values, values-v11, and values-v14 folders respectively. The default styles.xml sets
<style name="AppBaseTheme" parent="android:Theme">
the styles.xml in values-v11 sets
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
and finally styles.xml in values-v14 sets
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
This worked nicely for quite some time. I've checked the appearance for gingerbread using an emulator and the Holo-theme on a Galaxy SIII.
But now, also the Samsung phone will only use the classic android:Theme, no matter what I set in the style.xmls. I've also tried to raise the minSdkVersion in AndroidManifest.xml to 16 and to set the Holo-theme in the default styles.xml. Cleaning up and rebuilding had no effect either.
The Holo-theme is happily ignored by the app, and I don't know where else I can try looking to fix things.
Any help or pointers are very much appreciated.
Update
If I replace
android:theme="#style/AppTheme"
in AndroidManifest.xml with
android:theme="#style/AppBaseTheme"
everything works fine (AppBaseTheme is the platform-dependent parent theme for the customized platform-independent AppTheme). It somehow looks as if the Android runtime is lazy and does not care to look for the the most specific version of AppBaseTheme, but always takes the one found in values/styles.xml
Finally, after several unsuccessful cleans I took a different approach and tried to rename AppTheme to MyTheme (and updating the reference in AndroidManafest.xml accordingly). Now the app references the correct AppBaseTheme for each version of Android.
I have tried both Theme.DeviceDefault and Theme.Black in my styles.xml, and both make my 2.1 emulator become black correctly, but on the 4.1 emulator it stays white...am I doing something wrong?
<resources>
<style name="AppTheme" parent="android:Theme.Black" />
</resources>
PS: I presume the drop-down for "Theme" at the top of the Graphical Layout is just showing me what it would look like, it's not some kind of setting that's going somewhere (for the app)?
The Android system always chooses the most special values folder that fits best to your device.
As example if you have a folder values and another folder values-v14 the Android system takes resources from the latter if the device is v14 or newer.
Please refer to the Android documentation for more information.
1.create new folder under res -> values-v13
2.create file style there and add this style :
<style name="AppTheme" parent="android:style/Theme.Holo.Light">
in your manifast use this style for your application like this
<application
android:name=".MainApp"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
that way on ICS version you use the Holo.light theme and pre ICS use the default you already created
Setting it via styles doesn't actually work, but if you set it explicitly for application it works.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black" >
By default 4.0 and 4.1 give us white background but you can change it to black I face the same problem some days ago, if your project theme is set to be black then probably you change the Title while creating project to "Main" by default its "MainActivity" but if you change it to "Main" it will give you black backgrount/
I don't know my answer is relevant to your question or not but i think you talking about this if i am not wrong.