Loading different views depending on the android versions - android

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 .

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.

How to create all size layout in android studio by default Android 2.3.3

Is there other way except manually create all the layout folder like "layout-small,layout-large,layout-xlarge" ? Is there any automated function in android studio can automatically create these folder while creating the project?
As per my suggestion,there is no need for creating different size of layouts because we have a library by which we can set all dimensions according to devices.You can get the answer from my previous answer here.

Android different button styles depending on API level

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.

Load layout file based on platform version in my case

I know I can create /layout-v7, /layout-v8, /layout-v11 folders to allow my app to load the suitable layout for different platform.
BUT, the above way needs me to create different layout folders for all needed platforms.
I would like to have only two layout folders, if my app is running on platform with API version >= 11 , it loads from layout-x/, otherwise load layout files from layout-y/.
How to achieve this?
I would like to have only two layout folders, if my app is running on platform with API version >= 11 , it loads from layout-x/, otherwise load layout files from layout-y/.
Create res/layout-v11/ and res/layout/. And you're done.
I had this issue as well. The answer above prompted me to change the way I was doing it. I had a folder called 'layout-v8' and 'layout', thinking that if it matched to v8 it would use that one, and any other folder would match the regular layout.
So if you find it using the wrong folder, switch the way you handle the folder names. In this example, I created a 'layout-v11' which is v11 and greater, then my normal 'layout' folder is 10 and below.

reusable UI in android app

I am working on android app where I am thinking to develop reusable UI interface. How it can be developed and included in my .xml's
Here I want to develop a progress bar with my image and it will be display on some .xml's.
Please provide any code help.
I am a new in this field.
you can use <Include> xml tag within your layout xml,
read this :)
http://developer.android.com/resources/articles/layout-tricks-merge.html
I think you need to use styles and themes. Check this out.
You can either build custom (compound) views, look at Building Custom Components.
Or you can use Fragments. Fragments are new in Honeycomb (Android 3.0), but there is a compatibility library that adds fragment support to lower android versions (can be found in your ANDROID_SDK/extras/android folder). Or you can mix both of course.

Categories

Resources