I'm new to android and I've got a doubt that I couldn't answer searching.
I'm developping an application that would run from android v2.3 to 4.3. I know that the folders:
- values
- values-v11
- values-v14
containg the style.xml for each API level.
I want to apply the same exactly theme to all API levels. Right now, what I'm doing is copying the content of the xml to the other xml files in the other fodlers. But if I forgot to do that then the app looks different if the device has an android version different from the default one that I use (v2.3)
Is there a way so the app has only one style.xml file for all api levels?
Thanks!
The styles.xml located in the res/values directory is used by all versions, so use this one.
Related
I managed to get my adaptive icons working by creating a folder mipmap-anydpi and placing suggested xml file there (https://developer.android.com/guide/practices/ui_guidelines/icon_design_adaptive.html#studio)
This worked on api 26, but broke icons on android versions lower than that, they now show default android image. I managed to fix this by renaming my folder to mipmap-anydpi-v26, now icons work as expected on all supported apis.
My question is this, are we supposed to do it like this? Will -v26 make it also work on api 27+ or I have to create separate -v2X folder for each future api?
When you create a folder or a ressource file for a specific screen density or android version, this file becomes, in your case, the default reference for this version and the versions above.
Hope this helps.
I'm just starting to get into material design for android and I ran into small problem - material design guide says to create separate values-v21 folder and create my custom theme there, while all older versions will fall back to default values folder. By the time tutorial was released 21 Android version was the latest, so do I need separate folders for each subsequent android versions (22,23..) now and just copy same theme? Or will all later version will fall back to v21 theme if there's no newer version values folder?
No. Only create a /values/ and a /values-v21/ folder for your styles. This will be used by Android 5 and below and Android 6 and above.
If both folders exist with proper Styles.xml files, then Android 6 devices will use values-v21 and Android 5 and below devices will use values
I am creating a project that uses a big number of icons, in order to support multiple screens easily, I created the icons using vector graphics (SVG paths I believe they are called) which worked ok in my device.
Unfortunately when I tried to use it on older devices (anything with android less than 5.0) I get an inflater exception.
After searching I found out that in order to use vector graphics for those devices instead of using
android:src
I have to use
app:srcCompat
this indeed fixed the problem, but now when I deploy it to a newer device, the icons won't show (at least it doesn't crash though, so that's something)
Is there a way to define some sort of style to use according to api version
so that I can do something along the lines of :
<style name="android.api.21">
<item name="android:src">ic_menu</item>
</style>
<style name="android.api.19">
<item name="app:srcCompat">ic_menu</item>
</style>
Thanks in advance for any help you can provide
Just use the same style name (for example, styles.xml) and in resources folder (app/main/res) create different folders with naming values (common version), values-v21 (for API 21, Lolipop 5.0), values-v19 (API 19, KitKat 4.4) and so on and so forth.
I'm using HoloEveryWhere library with project having min target android:minSdkVersion="8". I converted Holo assets with custom color and I want to get those used with every platform version. However tested with Android 4.4 KitKat device and regular Button and EditText are not behaving the same than with older device. Also ActionBar behaves native way and not using the wanted Drawable I created for background.
With 2.3.x device everything seems to work just fine.
I see values-v11 and values-v14 in HoloEveryWhere values folder, do I need to modify these somehow?
Thanks.
Removing values-v11 folder from HoloEveryWhere values solved most of the issues. Also remember to set KitKat Style to NO if you are using Android Holo Colors to generate the assets.
I wanted to use Theme.Wallpaper in my app. This theme uses the phones current wallpaper as a background. The problem is it doesn't work on a 4.1 device. I also tried recreating the Theme.Wallpaper in my style resources but again it doesn't work for 4.1 devices.
- note that it may not work for lower APIs as well, I only confirmed it working on 2.2.1 and not working on 4.1.
I would like to know why it doesn't work and if there is any solution to that.
I have finally found the answer, it's a bit complex:
In a project built for a target above 14 (mine is 17) eclipse automatically creates a "values-v11" and a "values-v14" folders (applyed for phones or AVDs with api version 14 and above or 11 and above). In those folders are style.xml files that contain the "AppBaseTheme" style, This "AppBaseTheme" style replaces the one in the default "values" folder, which is the parent of (or: is extended by) the "AppTheme" style that is applyed by default to the application..
Now, the way I chose to apply the "Theme.Wallpaper" style to my app, was to have my "AppBaseTheme" inherit from it. Understanding this, it became obvious why my app did not have a "Theme.Wallpaper" like behavior on Systems with API 11 and above: I never made the alternative v11 and v14 "AppBaseTheme" extend the "Theme.Wallpaper" or the more suitable "Theme.Holo.Wallpaper" for v11, and "Theme.DeviceDefault.Wallpaper" for v14.
So, if you have troubles with applying styles, I hope you see this...
EDIT: if your reading this, and have troubles with editing the style.xml file in eclipse, try opening this file in any text editor (my favorite is notepad++) and just delete all the comments than reopen it on eclipse. In case you need comments just add them afterwords on your text editor.