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.
Related
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.
I'm trying to design a GUI using the Android GUI builder in Eclipse. I want to use the android.support.design.widget.TextInputLayout, but I don't see it in the palette view.
I have already imported the appcompat_v7 library into the workspace as a project and referenced to it from my Android project;
I have already imported the design support library into the workspace as a project and referenced to it from my Android project;
I've set the build path to Android API level 23 (the newest at the moment) to prevent errors like No resource found... from being issued;
I've cleaned all my projects;
I've restarted Eclipse.
How can I make sure the TextInputLayout is available in the palette view?
I haven't found a way to get library widgets to work (though widgets from the project itself do show up – though they don't always work, seems to depend on the widget).
However, there is a workaround: if you add them to the XML file, you can view and edit them in the visual editor. You can add the widget entirely by hand, or find its "native" ancestor: According to the docs, android.support.design.widget.TextInputLayout extends LinearLayout, therefore simply drop a LinearLayout into your layout, then go to the XML and change
<LinearLayout ... />
to
<android.support.design.widget.TextInputLayout ... />
Eclipse may add a xmlns:app attribute to your top layout (and then complain about it being invalid). Simply change its contents to
xmlns:app="http://schemas.android.com/apk/res-auto"
Whenever you edit attributes, Eclipse will add another xmlns:app1 attribute – simply delete it and change your widget's app1:* attributes to app:*.
The whole thing is a bit buggy and requires manual intervention, but works eventually.
I have started a new Android empty project.
Where can i find the graphical layout switch button ?
I have Eclipse Java EE and didn't installed any ADT plug-ins
because i am guessing they are already installed.
Do i need to put initial code before i'll be able to use it?
i read that i need to open the XML file to use the graphical layout,
the only xml file that i found is the manifest.
and accessing this file didn't get any result.
thanks,
Rami
You will find the layout xml files in /res/layout/*.xml.
These are the files that when opened will have a graphical editor.
If there aren't any then you can make one by using the new XML wizard.
My content assist was working for Eclipse XML (android) until I did an update of the android sdk, now the "design" of my xml files isn't a graphical view and when I use CTRL+space, I always get these four non-usable suggestions:
"default namespace - Default namespace attribute",
"noschemaLoc - no namespace schema location",
"schemaLoc- XML schema location attribute",
"xsinsp - XML schema namespace"
I also installed dreamweaver which may have interfeared with the XML extension.
A suggested solution is to right click on the .xml file and select choose another program called "Android Layout Editor". But I can't find it anywhere, I think it might not be on my computer.
I have also tried changing workspace without any success.
Any suggestions how to fix this ?
Right click on xml file and select openwith option and you can find Android Layout Editor.
If your content assist is working for java but not for xml, go to window-> preferences->xml->content assist and:
set the delay to 20 ms instaed of 500
set the suggestion strategy to LAX
add the entire alphabet to prompt when these characters are inserted: <=:azertyuiopqsdfghjklmwxcvbn
These are the things that worked for me, and programming with content assist is so much easier
;)
Update to ADT 16 which came out yesterday; the bug should be fixed there. ("The bug" being the bug that in ADT 14 and ADT 15, many newly added XML files would end up being assigned to the default XML editor instead of the customized Android XML editors.)
Re-install the SDK android-platform that you are working with. The resource files may be corrupted [e.g. android-sdk-windows\platforms\android-10\data\res\values\attrs.xml].
It's android sdk problem just change android currently version to another one
like if you are currently using android 2.3.2 than change it to android 2.3.3 i have tested it's currently working fine!!!
You can change it through PROJECT->PROPERTY->ANDROID now on that change version
Or you can set the default editor in Eclipse Preferences, used Android Common XML Editor.
You find it in Eclipse Preferences, General, Editors, File Associations. Click on .xml, choose "Add" "Android Common XML Editor". Select it and press the Default button.
very helpful i am jut following Step
click on xml file-right click on file -then choose the Android Layout Editor.
Is there any way to make Eclipse + Android SDK + ADT Plugin offer some sort of auto-complete in XML files if I hit CTRL+Space when my cursor is in a spot such as the ones marked with an * below.
<LinearLayout id* ... lay*>
The thing is that I think that the above was actually working already directly after the initial install - even though it of course never worked within style files.
<style name="ActionBarWrapper" parent="Fill_Parent.Vertical">
<item name="android:layout_height">36dp</item>
<item name="a*"
</style>
There is an icon in the eclispe toolbar to directly access the "new android xml file" wizard.
You could use IntelliJ IDEA instead of Eclipse, it has full auto-completion and works well for Android development.
http://www.jetbrains.com/idea/
The Community Edition fully supports Android, and is FREE
The latest ADT plugin (r9) does have partial auto complete feature in the layout xml.
for example, if you type ctrl-spacebar while the cursor is between 2 tags, you get the list of all avaliable tags (views and layouts). If your cursor is inside a tag, you get a list of all avaliable attributes.
First of all: Thanks for the good advice everybody. Not sure if the following should be an answer or a comment. Going for the answer because comments do not allow enough characters.
After trying out some eclipse plugins (like Rinzo XML Editor ) I found out that it actually worked for some files while it did not work at all for others. After some testing I am now under the impression that there is a difference between creating XML files via...
New > XML
and
New > Other > Android > Android XML File
I double checked that even when both files have exactly the same content (xml-version, encoding, namespace etc.) they behave differently with regards to auto-code-completion depending on the way of file-creation. I also checked the file properties but could not make out any significant differences. Obviously it must be something local or some meta stuff I am overlooking.
I think the different behavior is because when you create the file using "New->XML" the wizard opens the file using the default associated editor to xml content.
If you create a file using "New->Other->Android->Android XML File" I think the wizards tries to open the xml file using a specific xml editor, instead of the one you have configured as default, in this case Rinzo I guess.
In the second case why don't you try finding the xml file in either "Package Explorer" view or "Navigator" view, right click on the xml file and selecting Rinzo through the "Open With" option.