I can create folders with names values-21, values-22. But It will produce code duplication. Can I create something like values-21>= ?
For API 21+, you would have res/values-v21 . Take a look here http://www.metaandroid.com/question/primary-dark-color-android-under-api-21/
For this you need to have 2 values folder.
One that exist by default, and another, u have to create in your res folder and name it values-v21.
In the default values folder, in styles.xml, use theme other than Material theme And in the styles.xml of values-v21 folder that you created, use Material theme.
Android phone will automatically pickup the styles.xml which it support. If the phone supports Material Design (Lollipop devices), your app will use material theme (values-21 folder).
if it doesnt (in phones running older android versions), the default values folder will be used.
For more reference go click here
Related
I want to implement night mode in my app. I referred to this site:
DayNight Theme Android Tutorial with Example
I see we need to make the values-night directory and override the styles.xml file inside it. I already have other different values directory like values-v27 also overriding the styles.xml file. How do I implement the night theme for those specific directories? Like is it values-v27-night or is it values-night-v27? Is it even possible?
Of course you can have specific values for the night and for any other resource qualifier. For your example, the resource directory name will be values-night-v27.
If you are unsure of the order, you can right click the res node in your project structure and go to New > Android Resources Directory, then fill you criteria and the name will be automatically generated.
values-night-v27 puts an and clause between two conditions v27 and night , so it doesn't matter if you use values-v27-night.
Also if you put your values separately in values-v27 and values-night an or clause will be applied
I am writing app with android:minSdkVersion="14". Everything went fine until I tryed to add support for tablets.
When I created values-sw600dp folder and copied there the default dimens.xml file from values folder and tried to run the app on tablet, it started behave differently even when those dimensions file were identical.
ActionBar was gone, getActionBar() started to return null, EditText fields are orange framed instead of that blue underline, whole app design now looks like its on android 2.0.
On smaller devices where it still used default values folder everything is ok.
For testing, I tried to lower the 600 threshold (in values-sw600dp) to 300 to force this folder to be used even on smaller devices and result was same. ActionBar gone etc...
Sorry for english and thank you for answer
Ok I found solution to my problem. I accidentally coppied line:
<style name="AppBaseTheme" parent="android:Theme.Light">
into my dimens.xml file in folder values-sw600dp, which caused application to use Theme.Light instead of my default theme Theme.Holo.Light.DarkActionBar in folder values-v14. I donĀ“t know how it got there but I am glad I found it.
I want to use the
style="?android:attr/borderlessButtonStyle"
for my buttons. This requires min. API level 11. I want my app to be min API level 9. So I used the styles tag in the default layout folder and createt the folders res/layout-v9 and res/layout-v10 with the same xml-files as in the default layout folder - except for the style tag. I still get the minimum API level 11 error for the xml file in layout folder.
How can I avoid the error and apply the style-tag for API level >= 11 but not for API level < 11?
borderlessButtonStyle is part of the Holo theme, which is why it's not available below API Level 11.
You can however use that theme on earlier API levels by incorporating the HoloEverywhere project into your app.
If that's not what you're looking to do, you'll need to create a custom selector in your drawable folders and use that for button styling instead.
Did you look at the "Providing Alternative Resrouces" section in this article?:
http://developer.android.com/guide/topics/resources/providing-resources.html
Basically you add a suffix (called a "qualifier" in the linked article) "-v11" for specific API levels (so you would have a special folder named layout-v10, layout-v9, etc., each with the desired layout file in that folder). I'm not sure if there's a way to specify a range of API levels, though (i.e., less than 11, vs. greater than 11).
Just as an aside: this is what's actually going on with providing differently sized icons with the same name: you'll notice that Android projects created in eclipse have drawable-ldpi, drawable-mdpi, etc., as well as the "catch-all' drawable folders as a means for specifying alternative resources.
I have searched lot of sites for creating ICS holo style EditText in Android older versions. But the results did not helped me. Please provide me some sample links/code.
Copy the images from the android-sdk folder, and use them.
Search here for textfield_bg_*
/android-sdks/platforms/android-16/data/res/drawable-mdpi
Basically you want to download this xml selector drawable and put it as the background of each EditText:
https://github.com/android/platform_frameworks_base/blob/master/core/res/res/drawable/edit_text_holo_light.xml
(If you want holo dark then just replace each instance of "light" with "dark", obviously.)
Then you need to find each of the drawables referenced in that selector and download them into your res folder in the appropriate size category. You can use that github project to search for them - for example, the xhdpi version of textfield_multiline_default_holo_light can be found at https://github.com/android/platform_frameworks_base/blob/master/core/res/res/drawable-xhdpi/textfield_multiline_default_holo_light.9.png
You should probably use the HoloEveryWhere Library. It allows you to use the Holo themes on older API levels.
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..