Android studio do not update changes to layout design? - android

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.

Related

How to change default template layout files in Android Studio

As you know every time you create new project with some activity, Android Studio generates a default activity_main.xml file with RelativeLayout as the root element and one TextView. But I prefer to use LinearLayout without any nested views. How can I change the way Android Studio generates the default activity_main.xml?
You can do that by editing default template files, which are located in:
...\Android\Android Studio\plugins\android\lib\templates\activities
so for example, default layout file for template of EmptyActivity (note: this one is specific, the other ones have their own res folders) is located in:
...\Android\Android Studio\plugins\android\lib\templates\activities\common\root\res\layout\simple.xml.ftl
by simply replacing RelativeLayout with LinearLayout in your favourite text editor, you get what you want, but instead of that, I recommend you to make your own template, where you can define literally anything, according to your desires.
Edit: For the BlankActivity and a guide how to edit the other templates see this link:
How to change a BlankActivity template default files and a guide how to do it for any others.
in our course, we hacked the default activity. It worked as expected, still a side effect occured while upgrading from Android Studio 3 to 3.1.
The installation wizard detected the default activity template was modified and we had to replace our hacked version with a stock one.
So I suggest creating your own templates in the way Android Studio expects it (ie, through the template options) for a smooth upgrade process.

Android Studio - layout-land folder not appearing

I want to support separate UIs for both portrait and landscape mode in my android studio project, for which I need to have a folder with name - 'layout-land', to create it I followed below steps:
Right Click on res folder and create a new directory
Give name - 'layout-land'
Problem is- the created folder is not appearing within res folder :(
I am clueless, please suggest.
That's the slightly confusing 'android' view of Android Studio. It shows only one layout folder (also shows only one drawable folder) which really contains all folders. Switch the view to 'project' and you'll see all folders.
I'm posting this just in case anyone really likes Android hirearchy of the project (note: other answers using classic hirearchy are correct as well).
All layout dirs with different qualifiers are categorized under name "layout". Just right click on the "layout" create your xml with any qualifier you need and you'll get this hirearchy (image below).
Notice activity_main.xml is not a directorty but a category collecting all activity_main.xml files with different qualifiers.
This categorizing pattern appears quite often in Android hirearchy.

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.

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 .

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.

Categories

Resources