Recently I set my line length limit to 100 or 120 and I also enabled an option that will wrap the code that exceeded those limits to the next line, whenever I clicked Code Format.
Now I want to disable that wrap and do it manually, but I don't know where that setting was.
In Android studio go to
Preferences > Editor > Code Style > Java > Wrapping and Braces > Keep
when reformatting and uncheck the checkbox Line Breaks
Go to File->Settings->Editor->Code Style
There you'll find the two options "Right margin (columns)" and "Wrap when typing reaches right margin".
Related
I am using AS since 4 years. After last update I observed unexpected auto-formatting of XML layout (while typing and with Code -> Reformat Code too).
Here is an example:
When I started typing relative layout, it expanded start tag, width property, height property and closing tag in the same line.
Properties starts after indentation.
No space between views after reformat.
Question
Is this a feature in new AS? then how can I revert it back?
Did I change some setting? What setting should I modify to revert back? (I tried to find on google but could not find anything)
I am using
Android Studio 3.2.1
Build #AI-181.5540.7.32.5056338, built on October 8, 2018
Update
if you facing same issue with Android Studio 3.5 please check below article
Android Studio 3.5 Upgrade XML Reformatting Problems
Open File > Settings > Editor > Code Style > XML
Now in layout file make sure you have selected wrap attributes as Wrap always
Like below screenshot:
for me it's working
Open Settings > Editor > Code Style > XML > Arrangements
Click Set from... text
Select Predefined Styles > Android
Click Apply button
How to add line separator afer every method.
like this:
Simply enable in settings
Appearance: Show method separators
Or hit Shift 2 times in Editor Area and type method separators
Go to Preferences > Editor > General > Appearance > Show method separators > check the box
I can't figure how to Android Studio handle the styling of the foreach live template by putting it on two line like this:
for ( :
) {
}
In the Editor -> Live templates -> Android -> foreach we can unselect Reformat according to style and it stays on one line but it looks like a temporary fix.
I want to find where (according to style) is, to be able to modify it.
Thanks
I think it's a bug related with 'Reformat according to style' option.
As you know, to prevent wrong wrapping, turn off 'Reformat according to style" option for 'foreach' Live Template.
Editor > Live Templates > Android > foreach > Reformat according to style
Here is my explanation:
There are styles for 'for()' statement in
Code Style > Java > Wrapping and Braces > 'for()' statement
It makes wrapping when using 'Live Templates' with 'Reformat according to style' option. It's not about Code Style rule because it doesn't wrap when already typed foreach loop.
After some testing with template text and applying Code Style, I figured out the problem is WHEN Code Style applied. 'Reformat according to style' option is applied BEFORE template text interpreted, so Code Style for 'for()' applied to below text and it wraps.
for ($i$ : $data$) {
$cursor$
}
Type that template text in editor and 'Reformat Code', it wraps like this.
for ($i$:
$data$) {
$cursor$
}
That's why live template works like that.
It's just a bug and you can use the temporary fix until bug fixed.
The solution for me was simply going to the given place
Editor -> Live templates -> Android -> foreach
and unchecking Reformat according to style
You can modify it at the very same path you mentioned in the question.
Editor -> Live templates -> Android -> foreach
select foreach and at the bottom you see a textarea with the formatting/style. Modify it as you wish and click Apply
Update
The style you are referring to is i think the code style.
Can be found at
Editor -> Code Styles
Check this screenshot"
I just downloaded the ADT from google which included the Juno version of Eclipse.
After making a project however, the default text editor has this horrible dashed / dotted line between every horizontal line. It's a pain to look at, but Eclipse's appearance preferences always leaves me completely lost.
Any ideas on how to turn off?
Screenshot :
or link
http://imgur.com/BcOe9tV
I had the same dotted lines after choosing a darker color scheme in Eclipse and this fixed it:
Window/Preferences/General/Appearance/Jeeeyul's Themes/Edit/Underline Style: None
You probably enabled "Show Whitespace Characters" by mistake.
Is this what you're asking to turn it off?
If so, just click at this button:
Install Jeeeyul theme
Goto General > Appearance > Jeeeyul theme
Select Editor tab and set Underline Style to None, as shown in the screenshot:
These dots represent white-spaces between words/lines.
You can turn them on/off by going to Preference > General > Editors > Text Editors > Show Whitespace Characters
I found this option in Eclipse Luna. Juno should also have similar option.
Edit:
Alternatively, as #Leandro suggested, there is a button in the toolbar to turn it on/off
When editing XML layout files, Eclipse has a feature called 'wrap in container' (Reformat -> Android -> ...) that lets you select one or several Views and wrap a layout of your choice around it.
Is there something similar in Android Studio?
It's currently being implemented:
Issue 69000: Add the "Wrap In" visual refactoring - Android Issue Tracker
Tor Norbye, Android Issue Tracker Mantainer:
We should implement the "Wrap In" visual refactoring.
Just came across this, and to complete Simas' answer:
using AS1.2, this is easy to achieve...
to set up a Live Template, simply select the View in your layout XML
that you wanna surround. Hit Alt+Shift+Z (surround-with)... a little
popup appears. Click Configure Live Templates.... Or use File->Settings->Editor->Live Templates as described above.
Select the html/xml section and hit the little +. Give it a name and description, then fill in template text:
<LinearLayout
android:orientation="$ORIENTATION$"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
$SELECTION$
</LinearLayout>
Click Edit variables, set Expression:complete(), Default value:vertical... hit OK. Then, find the Define' button for applicable context... and select XML.
You're all set now. To use the template, select the View that you wanna surround in the XML, hit Alt+Shift+Z (surround-with)... a little popup appears. Select the template you just defined... Done!
You can use Live Templates for that. Here's a nice article about them.
Edit:
New templates can be added through File->Settings->Editor->Live Templates.
To find the hotkey for your keymap go to File->Settings and write "Live template". For me it's CTRL + J .