Android get an other style after adding value's folders - android

I have an application, that need to run in different size devices
For this, I added the next folders: res/values-normal and res/values-large.
Everything works fine except the application style was modified.
For example the Spinner was like the Model1 and after adding the folders it became like the Model2
http://postimg.org/image/cf3qa2oqd/
If I remove these folders, all returns as before (Model1).
Thanks,
NB: I was not able to add the image here.

the solution is:
change the Application Theme in the Style file
<style name="AppBaseTheme" parent="android:Theme.Holo">
it works fine.

Related

Design for new API but preserve compatibility

This line style="#android:style/Widget.Holo.Light.Spinner" makes my minSdkVersion go from 1 to 11!
How can I design my views for newer versions but still display ugly views for older versions (but allowing them to get the app) ?
The spinner is not supported on old versions. You can create the specific style that uses the spinner on a folder named values-v11, and on the style default folder (only "values") design a "ugly" spinner. Note that the styles must have the same name on both folders.
Check this answer https://stackoverflow.com/a/15339215/799979
The Spinner was added in API 1. It's the style you are attempting to use that is API 11+.
To solve this, you put another styles.xml file in the values-v11 folder. Then you have the Spinner use a style from your styles.xml file. In the styles.xml file in the default values folder you have your new style inherit from the android style you want to use. In the styles.xml file in values-v11, you modify that same style to use something can be used in older APIs.

Activity as dialog using HoloEverywhere cuts off layout

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>

Android Where to place different icons for different themes?

In my application I have different Themes - one dark and one bright theme. Each theme requires his own icon set.
How do I apply it to the theme? Is there something like a special folder like for icons with different sizes ?
The following serves as a hint...
I suppose this may help: http://developer.android.com/reference/android/R.attr.html#icon
Lets say you have the following themes...
<style name="MyTheme.Dark">
...
</style>
<style name="MyTheme.Light">
...
</style>
You can add <item name="android:icon"></item> to each theme and supply each one with their own drawable icon. Then to get the respective drawables in your layout or what have you, you need to make use of ?android:attr/icon.
So your layout may end up looking something like...
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:attr/icon"/>
If you're unsure about what the ?android:attr/icon part exactly means, read http://developer.android.com/guide/topics/resources/accessing-resources.html#ReferencesToThemeAttributes.
Is there something like a special folder like for icons with different sizes ? (up to my knowledge) NO
no such default folder exist which you can use for Themes.
You need to do it programmatically.
Save the theme info in your Shared Preferences.
and at time of loading the view you can set your desired themed drawable.

where do I place themes.xml?

In what directory do I have to place my themes.xml in order that my android recognises the correct version?
I have two versions of themes.xml. One is used by tablets. And the other one shall be used for phones with large screens. I placed the one for tablets in the folder res\values-v11\themes.xml and the other one in res\values\themes.xml
Unfortunately someting doesn't work. I definied a textColor for textViews in each of the files with different colors, so that I can recognise the file which was chosen by the OS on different phones. It worked perfectly on a xoom tablet with android 3.2. On a galaxy s2 with 2.3.5 it doesn't work.
What am I missing?
Here are the styles I use:
Tablet:
<style name='MyTheme' parent='android:Theme.Holo.Light'>
<style name='MyAutoComplete.red' parent='#style/MyAutoComplete'>
<item name='textColor'>#color/red</item>
</style>
Non-Tablet:
<style name='MyTheme' parent='android:Theme.Light.NoTitleBar'>
<style name='MyAutoComplete.blue' parent='#style/MyAutoComplete'>
<item name='textColor'>#color/blue</item>
</style>
Since your requirement is to track OS version by textView's color.
I have following suggestion. (Colors are for example only, you can change yourself)
res/values -> Yellow Color // Phone using 2.3.* or before
res/values-v11 -> Red Color // Phone using 3.0 or later
res/values-xlarge -> Green Color // Tablet using 2.3.* or before
res/values-xlarge-v11 -> Blue Color // Tablet using 3.0 or later
So a Xoom should show Blue, a S2 (2.3.*) should show Yellow, a Galaxy nexus should show Red.
You need to create a theme in styles.xml and place it in res/values folder.
Put "Tablet" in res/values-xlarge and "Non-Tablet" in res/values
You need to have two seperate xml files for the two themes to able to run the theme in the two seperate devices
Place both in resource :)
Hope it helps

Style / themes not working

whenever I try to apply a VERY simple style in eclipse I get errors:
the style is as below (filename styles.xml in res/layout)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="commonStyle">
<item name="android:background">#EEEEEE</item>
</style>
</resources>
Regardless of whether I try to apply this to a LinearLayout (using style="#style/commonStyle") or to an activity in my manifest file (using android:theme="#style/commonStyle") I ALWAYS get the error "No resource found that matches the given name...".
If I try to apply an Android theme to an activity (say Theme.Black) it works just fine.
If I remove any usage of my style, my R.java file is generated as normal with the following contents:
public static final int styles=0x7f030002; (in the generated layout class)
I have NO idea what is going on. It seems that NOONE is having the same troubles as me (Ive spent about 4 hours searching using google, and came up with not even a remotely close answer).
Ive tried restarting eclipse, clean building etc. etc. and nothing works what so ever...
So what am I missing?
Try moving your styles.xml file to res/values.
http://developer.android.com/guide/topics/resources/style-resource.html
Styles need to be stored in the res/values folder :)
http://developer.android.com/guide/topics/ui/themes.html (See Defining Styles)
The name of the XML file is arbitrary,
but it must use the .xml extension and
be saved in the res/values/ folder.
I haven't used styles in my code yet, however generally you need to use
android:
Does it work when you use this?:
<style android:name="commonStyle">
Please verify the you call the style in the correct manner :
for example this might compile but will not work :
style="mainButtonText"
this is the correct way to call style:
style="#style/mainButtonText"

Categories

Resources