MinSDKVersion = 7
TargetSDKVersion = 17
If the user have SDKVersion 11 or higher I like to set the theme to Theme.Holo.Light.
It doesn't works for me here. When I launch the app on a 3.1 device it just uses the Theme.Light:
Same when I run this app on a device with lower version than 3.1
My Folderstructure:
Manifest:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/MyTheme" >
values-v11:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="#android:style/Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="#android:style/Theme.Light">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<!-- Any customizations for your app running on devices with Theme.Holo here -->
</style>
other values folders:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="#android:style/Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="#android:style/Theme.Light">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="MyTheme" parent="#android:style/Theme.Light">
<!-- Any customizations for your app running on devices with Theme.Holo here -->
</style>
How can I use this correctly?
Sincerely
Marco Seiz
Why do you have your theme twice in your styles.xml file?
<style name="AppTheme" parent="#android:style/Theme.Light">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<!-- Any customizations for your app running on devices with Theme.Holo here -->
</style>
Delete the one you don't need(In this case the Theme.Light theme):
values-v11:
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<!-- Any customizations for your app running on devices with Theme.Holo here -->
</style>
values:
<style name="MyTheme" parent="#android:style/Theme.Light">
<!-- Any customizations for your app running on devices with Theme.Holo here -->
</style>
Place the solution provided by #Ahmad in new files called themes.xml on the directories he said :-)
If you'll use multilanguage and multithemes, you can take a look at a similar question I did some minutes before... and got answered:
Multilanguage and multitheme at same time
Related
I am using the following style to change the menu to lower case but it does not work.
I've searched on the internet for references but I couldn't find anything.I think there is problem with the library.If anyone has an answer please tell me.
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="actionMenuTextAppearance">#style/MyMenuTextAppearance</item>
<item name="android:actionMenuTextAppearance">#style/MyMenuTextAppearance</item>
</style>
<style name="MyMenuTextAppearance" parent="TextAppearance.AppCompat.Widget.ActionBar.Menu">
<item name="android:textAllCaps">false</item>
</style>
i have app which was created in android:Theme.Light. i want to change it to Theme.AppCompat.Light.DarkActionBar but i get
no resource found that matches the given name
'theme.appcompat.light.darkactionbar'
I have android-support-v4.jar, when i try add appcompat_v7 i get errors in codes where is something like it R..... Can I add DarkActionBar to this project without problems with codes? Without changes in code?
I have:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
I want:
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
</resources>
Ensure that your application is properly linked with the Support Library, with resources (see documentation here).
And don't forget #style/:
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
This will prevent the no resource error from occurring.
You might be interested in this tutorial too.
If you're doing this in your manifest, do the following to set the theme for the whole app:
<application
...
android:theme="#style/Theme.AppCompat.Light.DarkActionBar"
...>
in your XML for the specific theme, you need #style, so put the following:
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
I know the question seems simple, but not anything like chei here before. So there you go:
In my android application using the Support Library with AppCompat v7, added an ActionBar. Everything works perfectly, except that when the application runs on android 2.3, the background of the ActionBar is dark, and when the squeegee android 4.0.2 ActionBar this background turns gray.
Below is how to define my #style
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
how can I solve this?
This will not work for you on min target as 2.3.3 in case your min target is API level 11 you can change the background color
<resources>
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">ANY_HEX_COLOR_CODE</item>
</style>
</resources>
I would like to add my observation (using min sdk 8, target sdk 19) for the future readers on this issue.
If you want to set just the background color of the action bar across different android versions, its easier to do it in code.
actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable( getResources().getDrawable(R.color.your_desired_color));
This overrides the default background across versions and set your desired color.
Note: I had seen on various post and tried to set the background color as follows:
ColorDrawable colorDrawable = new ColorDrawable();
colorDrawable.setColor(R.color.your_desired_color);
actionBar.setBackgroundDrawable(colorDrawable);
but it did not work, reason unknown to me for the time being.so I successfully tried the code mentioned above.
if you want to set the background color of the action bar (along with other attributes) not in code, you can use style and theme. I had done the styling as follows.
inside res/values/style.xml
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- API 11 theme customizations can go here. -->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<!-- custom theme for my app -->
<style name="MyAppTheme" parent="AppTheme">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/bgcolor</item>
</style>
</resources>
inside res/values-v11 and res/values-v14
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- API 11 theme customizations can go here. -->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<!-- custom theme for my app -->
<style name="MyAppTheme" parent="AppTheme">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/bgcolor</item>
</style>
</resources>
Note:
As I had to have similar look for the action bar across android versions, I had copy-pasted the code in res/values-v11 and res/values-v14 from res/values. But to my surprise,I did not get the desired result. Reason? We need to add the "android" namespace before the tags for android v11 and later. So I changed actionBarStyle to android:actionBarStyle and background to android:background. That brought me the desired result.
I've an app which may be ran from 2.2 to 4.x devices.
When I run this app on 4.x it looks cool, holo style. But when I run it on older devices, it seems to be so much "lighty".
There's a screenshot so you can compare:
This is my manifest:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
And my styles:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.NoActionBar.Fullscreen">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
It's obvious that holo doesn't exist in 2.3, but then it should render its default device theme, right?
So the input is correct, but the TextView looks too grey.
Any idea?
As someone suggested, I finally created a new folder:
res/values-v11/
On this folder, I've put a file named styles.xml, which is the following:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.NoActionBar.Fullscreen">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
And the folder res/values/ which will be called for android with api lower than 11, contains a styles.xml and there I've changed the parent template, like this:
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="MyTheme" parent="#android:style/Theme.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
This ends up like this:
Devices with api higher than 11 -> holo theme
The rest: Theme.Light ("Normal theme")
I want to add small lines under the Edit Texts like the following , How can I do that ?
This is by default look of Edittext in Holo Theme. so just apply Holo Theme.
if you want to apply Holo Theme. set
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="17" />
and styles.XML inside values-v11 folder
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 11 theme customizations can go here. -->
</style>
and styles.XML inside values folder
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light.NoTitleBar">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="progressbar_holo" parent="#android:style/Theme.Light">
</style>
and in AndroidMeanifeast.xml
android:theme="#style/AppTheme"
in application TAG.