Android studio - wrap in container - android-studio

Is there an equivalent feature in Android studio like Eclipse for "wrap in container"?

On the widget press alt+enter and choose what you want!

For Mac ... same as above but use option+Enter.

UPDATE(2021): Currently, Android studio support wrap in content and you can follow this answer: https://stackoverflow.com/a/59217255/1105277
Original Answer(2016):
You can use soft wrap, first solution is right click on the left of line where show line numbers and check Use Soft Wraps.
Another way is set it from:
File > Settings > Editor > General > Use soft wraps in editor
Also You can set Right margin for your editor from :
File > Settings > Editor > Code Style > Right margin (columns)

Related

Android Studio: Code Folding turned off but not applying to imports

I have turned off Code Folding using the procedure described here.
However, my imports are still folded away, hidden by an Ellipsis, as shown here:
I really don't see the point of having code hidden away so that extra key presses or mouse clicks are required to see it.
How can I make Android Studio just show me everything?
Launch Android Studio
Configure > Settings > Editor > General > Code Folding
Uncheck "Imports"

How to set max line length in Android Studio code editor?

How can I set a maximum length for Android Studio's code editor, or may be set a word wrap?
In my Android Studio, no matter how long a statement I type on a single line, it never automatically goes to the next line, but rather a horizontal scroll bar appears.
When I autoformat using the Ctrl+Alt+L (reference), nothing happens.
My SO or Google search found a lot of material on this for Eclipse, but not for Android Studio.
If you need not a soft wrap,
but actually, brake one long line onto several lines you need:
Go to Preferences(mac) or Settings(windows) -> Editor -> Code style -> Java/Kotlin -> Wrapping and braces (tab) -> Check "Ensure that right margin is not exceeded"
Now try to reformat your code:
press
OPTION (ALT) + CMD + L on your Mac
(or CTRL + ALT + L on PC)
Edit 13.02.19
As noted in comments this option seems not available in settings for Kotlin.
However, there is a workaround to manually add it.
Here is what it takes to make it work:
Export the settings scheme.
Open saved xml file.
Find <codeStyleSettings language="kotlin"> tag (or create)
Add the WRAP_LONG_LINES setting manually:
<codeStyleSettings language="kotlin">
...
<option name="WRAP_LONG_LINES" value="true" />
</codeStyleSettings>
Save edits and and import back the scheme.
Here you go!
MacOS:
Click on Android Studio ( left top corner )
Click Preferences
Type Code Style in search
Click on Code Style
There is a filed right to the 'Hard wrap at' - you can enter needed about of symbols you need
In File | Settings, select "Editor", then "Code Style". There is an option "Wrap when typing reaches right margin".
Edit: Just tried it, and it doesn't seem to work. Anyway, maybe the option "Use soft wrap" in the "General" group is more what you want.
#Solace, actually #Fahim Faysal's answer is quite close to what you need, but since you want to solve the problem no matter how long a statement I type on a single line, it never automatically goes to the next line, 2 more steps you need to follow:
[Step 9] type the max length you prefer at `"Hard wrap at" ()
[Step 10] change "Wrap on typing" from Default: No or No to Yes
With version 4.1.2 and with Dart language you need to go to "File/Settings/Editor/Code Style/Dart" and modify the "Line length" to the preferred number.
In Android Studio:
File->Setting->
Editor->code Style->java->Wrapping and braces(tab:right side)->keep when reformatting->Line break(make unchecked)
You can change the max column width from:
File > Settings > Editor > Code Style > Right Margin (columns)
Android Studio 3.5:
Mac -
Android Studio > Preferences > Editor > CodeStyle > HardWrap at: ____
The existing answers already answer the question in straight forward way. As a different approach you could set the style guide to kotlin style guide code style. Then if you do alt + ctrl + l as you did, you'll see auto wrap as you expected.
Just open the settings, search for kotlin and look for kotlin under code style.
On the top right hand side of the settings window you'll see Set from..., click on it.
Then on predifined style > kotlin style guide
If you'd like to follow the kotlin formatting style this could reduce more effort. For more information: https://developer.android.com/kotlin/style-guide
My Environment:
Ubuntu 18.04
AndroidStudio 3.3.2
My operate:
File -> Settings -> Editor -> Code Style
Scheme -> select Project
Hard wrap at '120'
Apply
To move the grey vertical line, that tells Android Studio where to wrap your code, go to
Settings- Editor- Code Style- Java or Kotlin- Wrapping and Braces- Hard wrap at
and enter the number of characters, where the line should be.
For dart
settings => code style => Dart => Line length
In settings/code style/kotlin/wrapping and braces replace the "do not wrap" values with "wrap if long"
You can change the Hard wrap at param

Android studio automatically open's documentation view

I don't know if it is bug or kind of setting, but it is very annoying while typing value i.e. android:layout_gravity="", it opens hints with dropdown, and after a while the documentation view gets opened and hides the dropdown with hints.
I checked that no button is suspended or anything like that. I use Ubuntu 14.04.
Strange, because I've not changed anything with AS from months and there was no such behavior before. There's solution:
Follow the simple steps to remove open Documentation by cursor move :
Android Studio -> File -> Setting -> Editor -> General
Right side of the screen go to Others :
Uncheck checkBox show quick documentation of mouse move & Apply.
Preferences > Editor > General > CodeCompletion > uncheck Auto popup feature
I found out that I don't want to disable the documentation.
Instead, I set the window to be 'Opened as Popup',
This displays the documentation aside to the cursor and autocloses it automatically.
Surely I've set it before as a 'Tool Window' to see the full content and then I forgot to set it back.
Note that this functionality has been moved recently. It's now in:
Android Studio -> Preferences -> Editor -> General -> Other.
Uncheck "quick documentation on mouse move".
Studio 3.4.2, somehow had setting checked, uncheck it.
File -> Settings -> Editor -> General -> Code Completion.
Cheers
This the only correct answer as far i know because i sorted out this way only. Just click on Help>find Action>auto(in the search box)> and uncheck the checkbox in the image shown
For Android Studio 4.x ~ Arctic Fox | 2020.3.1
Preferences > Editor > Code Editing > Quick Documentation > Show quick documentation on mouse move: unchecked

Android Studio 0.8.2: Remove Vertical Line Break

Been searching through the editor settings for quite a while but I can't figure out how to turn off the vertical line break in Android Studios 0.8.2. Driving me crazy!!!
It was driving me crazy as well. For older versions (like 0.8.2), Open the Options and uncheck:
Editor -> Appearance -> Show right margin
More recent versions use:
Editor -> General -> Appearance -> Show right margin
AS 3.x:
Editor -> General -> Appearance -> Show hard wrap guide
With Android Studio 1.2.2
File > Settings > Editor > General > Appearance
Or you can just write in the search box of Settings: "right margin"
In Android Studio 1.1.0:
File > Settings > Editor > Appearance > Show right margin (uncheck)
update:
AS 3.x:
Editor -> General -> Appearance -> Show hard wrap guide
In Android Studio 3.1.2, Show right margin is replaced by Show hard wrap guide. (I don't know in which release, this change rolled-out)
Uncheck highlighted option and save. The vertical code line indents will be gone.
File > Settings > Editor > General > Appearance > Code Style > Hard Warp at
Even I'm afraid of down votes but I don't understand why you guys want to hide this line, don't you think it's really useful ?
It helps us know when we should make a new line to match coding convention (code-line width). And the short code-lines (max 80-120 characters) make your code:
Readability
Easier to review code before committing it to the repository (without horizontal scrolling).
Easier to track changes of the committed-history (without horizontal scrolling).
Work with two files at a time (Split vertically in Android Studio) (without horizontal scrolling).
This unbelievably annoying line is the default in various editors. Netbeans, Eclipse, LiClipse, VS Code, and now Android Studio Chipmunk 2021.2.1 Patch 1 for Linux 64-bit.
I had to click on File > Settings > Editor > General > Appearance and remove the checkbox on Show hard wrap and visual guides (configured in Code Style options).
I remember this used to be called a print margin or something in Netbeans. This vertical 80 character limit line is a tad hard to find in the IDE settings and often difficult to search the internet for the correct settings to disable it too. The variety of answers on this page shows how much the Android SDK team has changed the IDE too.
People have discussed the relevance of such a vertical line here, here and on various other websites. Since the percentage of people who hate it are lesser than the percentage of people who like/tolerate it, I guess IDE's are going to continue keeping it as a default.I wouldn't mind it if that line's colour was at least a lot more subtle.
This very annoying vertical line that you will find with the android studio chipmunk release by default. There is no easy way to disable it as it is difficult to find.
It is under
Preference->Editor->General->Appearance
Uncheck []show hard wrap and visual guide(Configure in Code Style option)
That works on chipmunk release.

XML attributes order in Android Studio

I'm facing problem with keeping proper order of XML attributes in Android Studio. As you can see below, the style attribute is between layout_* attributes, but I want it to be ordered by name (like in Eclipse). I'm using standard Intellij code formatter and the Android Studio gives users ability to set your own rules regarding XML ordering. The settings are located in Code Style -> XML -> Arrangement, but it seems not to work or I'm using it wrong. Any ideas how to order XML attributes by name using default code formatter?
<TestView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
style="#style/BackgroundLight"
android:layout_height="wrap_content">
</TestView>
Finally got it.
Choose File > Settings > Code Style > XML > Set from > Predefined Style > Android
Set File > Settings > Editor > Formatting > Show "Reformat Code" dialog
Run formatting on a XML file (CTRL+ALT+L by default)
You will see a popup window, set the Rearrange entries flag
Disable Reformat Code dialog in the settings
This way every XML file formatting will set the attributes in a proper order.
Edit:
Starting with Android Studio 0.2.6 release the XML Android style formatting is set by default, but you still have to set the Rearrange Entries flag manually.
http://tools.android.com/recent/androidstudio026released
Automatically apply the Android XML code style if a code style hasn't
already been customized. This will make it possible to automatically
order XML attributes (check the "Rearrange Entries" checkbox in the
"Code > Reformat Code..." dialog.)
UPDATE: the method I described below is an official way to fix this known issue, see: https://developer.android.com/studio/releases
After updating to the newest Android Studio v3.4.2 I found that it doesn't format XML code properly anymore. For instance, attributes ordering didn't work in layouts. It did indentation and namespaces ordering only.
I don't know the reason why it was broken after an update but was lucky to fix this:
Go to Settings (CMD + , ) on Mac.
Type format in Search box and click on Editor -> XML setting.
Click on the Android tab and make the same settings here as it's on a picture:
Settings on a picture quite normal, but of course you can tune this tab setting up to you.
Go to the Arrangement tab and you will see something like this:
The reason why attributes are not getting sorted - sorting rules are empty.
To fix this:
Choose Scheme and play with Default IDE and Project options. Switching between them may help.
Or choose Scheme which suites your needs and then click on Set from... blue text in right upper corner -> Predefined Style -> Android. You will see restored rules in the window:
I also chose Force rearrange - Always
To save result – click Apply.
Also you can click on a gear icon near Scheme and copy settings or even restore defaults.
P.S. To me standard rules are comfortable, but it can be customized further. Here is an article which may help doing this: https://medium.com/#VeraKern/formatting-xml-layout-files-for-android-47aec62722fc
Go to your layout XML
Try Ctrl + alt + shift + L then find checkbox label is Rearrange code and checked its.
To delete empty lines between them:
Preferences > Code Style > XML > Other > Keep blank lines: 0
And then just reformat your XML files.
There is a plugin for IntelliJ which might do what you're after...
http://plugins.jetbrains.com/plugin/?idea&pluginId=6546
File > Settings > Editor > XML > Arrangement Select Scheme and choose Default

Resources