When I am editing a layout file is there a way to get eclipse to autocomplete my strings references from strings.xml.
For example if I have a layout node like this...
<PreferenceCategory android:title="#string/settings_category_stay_intouch_title">
It would be great if I could type the #string/settings_ part and then use alt+space like I can when I referencing the R.string in a source file.
Right now I just get "No XML Template Proposal"
Any tips for configuration or plugins would be appreciated. I use strings.xml extensively and I have a ton of layout files so flipping back and forth between strings.xml and my layouts as I work on them is a bummer.
Well it should work. Try using on windows CTL+space.
I tested with latest ADT 16.
Related
1.) Is there any reason to have a default value inside an android xml layout?
Ex.) The TextView below has included a default value of
android:visibility="visible"
`<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:visibility="visible"/>`
Conjecture: Because this is a default value, it has no effect, and therefore is an unnecessary line of code in the XML file. Is that line of thinking correct?
2.) If there is no reason for default values to exist in Android xml files, is there a lint plugin available to point out default value code lines in android XML files?
It is my thought that a large number of code lines in XML files are default values, serving no purpose. What can we do to reduce these lines of code?
U can create a style with your default values and use it.
For example:
<style name="DefaultTextViewStyle">
<item name="android:visibility">visible</item>
</style>
to use this:
<TextView
style="#style/DefaultTextViewStyle" />
I had some hope that the Lint inspection Redundant default value attribute assignment for xml, run via Android Studio might have done what you're asking. You can run it as specified under the Manually Run Inspections part of the Android docs. i.e.Android Studio -> Analyze -> Run Inspection by name -> enter "Redundant default value attribute assignment", then select the scope for the Lint check.
Sadly though, it doesn't pick up the case you mention above. I'm just wondering if there's something I've missed, or if this isn't intended for Android xml in some way?
On Android Studio is there a way to remove unnecessary spaces between the attributes and 'end tags' (">" and "/>") when formating xml files?
I can't see this configuration "Code Style" options.
Based on the accept answer below I got a configuration that work for me:
In Android Studio's Preferences, go to Editor > Code Style > XML. Then select the Android tab on the far right. There are options in this tab to customize the formatting of Android XML files (manifest, layouts, etc.). Make sure Use custom formatting settings for Android XML files is checked. Then you can just format that file like you do any other file Code > Reformat Code.
To get rid of the space before closing tags, go to the Other tab. Under Spaces make sure In empty tag and After tag name are un-checked.
Background
Lint has a relatively new feature, so that it will warn us about missing translation only for languages that we choose, but i don't get how to use it.
The problem
for some reason, Lint still warns me about languages that i don't intend on translating yet.
What i've tried
for example, currently i want to only have 2 languages : english ("en") and hebrew (which is sadly both "iw" and "he" ) .
so i have strings files in the folders :
values (for english)
"values-he" and "values-iw" (for hebrew) .
i've tried putting the new attribute in the english file as such :
<resources xmlns:tools="http://schemas.android.com/tools" tools:locale="en,iw,he">
...
The question
what is the right way to do it?
Looking here it seems that it's to be used into resource files to indicate the default language. So you can specify only one locale code.
should correspond to a language
Moreover it seems to be used only to disable spell-checker
If you read the article:
This lets you tell the tools which language you're using in your
base values folder. For strings in for example values-de or values-en it's obvious, but not in the base "values" folder
It need only to know what is the language in the default "values" folder (the folder without any attribute).
<resources xmlns:tools="http://schemas.android.com/tools" tools:locale="en">
You are already in right direction. Just need some modification. Like this manner:
<resources xmlns:tools="http://schemas.android.com/tools" tools:locale="es">
Now we know that the language used for strings in the default values folder is Spanish rather than English.
Used by: Lint, Studio (to disable spell checking in non-English resource files)
Reference Link: Go to here tools:locale
Thanks.
There are similar questions, but none address my specific issue.
I'm rather new to Android development and Eclipse but was able to follow the tutorials A OK.
In fact, I'm able to edit activity_main.xml from a tutorial, but now, in a test project I'm working on, I can't edit my new activity_main.xml (again, different project, same filename).
I created the file by right-clicking on the layout folder then selecting NEW > OTHER > Android XML Layout File. I was able to copy some of the other file so that my file now looks essentially like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
</LinearLayout>
When I type, the cursor moves around (looping through the text) but no characters appear on the screen. Again, in the other XML file I can edit with no problem.
I'm hoping that this is just some newbie problem.
I have had similar problems, though not this exact problem. Sometimes simply restarting Eclipse, or whatever editor you use, can help. Occasionally, Eclipse will not detect changes in your xml so you need to clean and rebuild the project. You can do this by
Winodow --> Project --> Clean...
and choose your project
I know there was an issue that I had which was similar with the editor jumping/replacing lines and such which I believe was fixed in a newer version of Eclipse. If I can find a source later I will edit
Clear all of text in layout activity_main.xml (in code view)
Drag and drop new LinearLayout in layout (in graphical view)
Go to Project -> Clean
I've looked at several other questions related, one answer even seemed like it solved the problem however I was wrong.
The issue is I get:
Parser exception for C:\Documents and Settings\djordan\My Documents\SampleTest\AndroidManifest.xml: The markup in the document following the root element must be well-formed.
When I drag/drop a new TextView or Multiline Text view item to the canvas. All other Text Fields add fine.
EDIT: Pasted the wrong error ... updated. and Added following work flow:
1. open SDK, check API 16 installed.
2. open Eclipse, create new Android project
- name, target/minimum API 16
3. in Graphical Layout drag "Plain Text" or "MultiLine Text" from the Text Fields.
4. view error above.
Flip over to the xml page, go through and find the textView you just added. Find the attribute where it says android:textSize="18" and change it to android:textSize="18dip" That should solve it. The error is telling you that the units for that attribute are not valid or were not set.