Android different button styles depending on API level - android

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.

Related

Android studio do not update changes to layout design?

I have notice that Android Studio doesnt update changes made to layout and it always displays old layout design. so i went to check layout folder in explorer and notice that it has three different layout folder namimg : layout , layout-v17 and layout-v20. I have notice that both layout-v17 and 20 contains old layout and was never updated with new layout design. so i have deleted those two folder and it started working . Is it a good idea to delete them
If you didn't create spcial versions of your layouts for particular api versions, it is ok that you deleted the folders.
That kind of folders are used to keep resources for specific api versions. E.g. you can have an activity_main.xml layout in layout folder and in layout-v17 folder. Then, the layout from the default folder would be used for devices with api level < 17 and the layout from layout-v17 for sevices with api level 17 and higher.

Same style on all API using AppCompat

I'm using com.android.support:appcompat-v7:22.2.0 to make Lolipop material design on pre-Lolipop devices. The problem is that widgets (example EditText) are displaying different views with different parameters on different API.
Question is how to make it all looks the same on all API 15 and above?
Example here (different bottom line, margin between text and line etc.):
I think that I found solution.
AppCompat generates proper look during inflating layout.
If API < 20 it generates look like newest API (ex. 22).
If API >= 21 it generates look depending on API.
Don't look at preview in XML (my image is from previews). Open emulator and check by yourself how it will looks on device.
Hope it helps someone in future.

How to create resource folder for android 21 api and higher?

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

How can I style the ActionbarSherlock Tabs in Android API 11+?

I just wanted to give my actionbarsherlock tabs another color. Therefore, I found this interesting article: Styling the Actionbarsherlock tabs
Now, my problem is that for me it only works for API level before 11. What am I doing wrong? I implemented the code from the solution just like that.
One other thing that I did, was increasing my API level (from 7 to 11) because this line from the code in the article
<item name="android:actionBarTabBarStyle">#style/Theme.app.tabbar.style</item>
produced this error:
android:actionBarTabBarStyle requires API level 11 (current min is 7)
Any ideas?
For just API 11+ you can create a folder in res called values-v11 and make a style file in there, then only those styles will be applied if the API is level 11 or greater.

Loading different views depending on the android versions

Well, I was wondering whether I could load different views from same application for different android versions. I thought that I could create an activity that can call one of the two separate activities defined for different versions of android via intent. I mean suppose that in one activity I have used action bar which is available from ice cream sandwich only, and other could possibly to use views in earlier android releases.
1) For layout that support multiple screens you can refer this
2) If you want to load different layout depending on different android version then you can create different layout xml files and then in the activity, for example below code
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
// only for android older than gingerbread
//call setContentView with your layout
}
3) You can have layout in layout-v(version-number) folder inside your res folder. Where for example for SDK 11 the folder name will be layout-v11
Yes. Create a layout-vX folder in your res, where X is the version number (11 for Honeycomb, for example). Any file in there will override the version of the file in the layout directory if using version X or higher.
if all you need this is for the action bar , i highly recommend using actionbarsherlock library .
you can also do the checking of the version using code (read here) :
if(VERSION.SDK_... <VERSION_CODES.... )
and by setting the qualifier of the version , as written here , so for example, for resources that need to be used on API 11 and higher , put the qualifier v11 .

Categories

Resources