Android Studio doesn't align my code by attributes - android-studio

When I'm working in Android Studio and I want to make, for example, a new button. I type button and Android Studio gives me the correct line for inserting a button. When I press enter, Android Studio inserts it but it puts it in one line (see image)
But I want the code to be sort by attribute (see image)
The last one, I see in every tutorial, but mine doesn't do it automatically.
Does anyone know how to fix this? Now it takes so much time to align the code.

You can reformat your code with the below keyboard short cut.
Ctrl + Alt+ L
This short cut will format you complete file code. Whether that is XML or Java Code.
Hope this helps you.
Alternatively
You can do the same by going to your IDE Main Menu and selecting Code > Reformat Code or if you're only fixing alignment of text then Code > Auto Indent Lines.

Related

I've accidentally added a number label in front of a file in Android Studio and I'm not sure how to get rid of it

I was trying to refactor a filename in Android Studio when I accidentally mistyped the keyboard shortcut.
Since I have a 75% keyboard, I don't have F rows. So I tried to hit Shift+FN+6, which would result in inputting Shift+F6, which is the keyboard shortcut for refactoring. But because of my typo, I hit some other keyboard command. Probably did <some keys> + 6 by accident.
Now there's a little 6 label listed in front of the filename:
Does anyone know what shortcut I accidentally hit, so I can undo it? I found an SO user who did the same thing as me but he got no replies. I tried hitting a bunch of random shortcuts and looking in the options menu but I can't find the option that I must've hit.
https://resources.jetbrains.com/storage/products/intellij-idea/docs/IntelliJIDEA_ReferenceCard.pdf
Android Studio is based on Idea and inherits its features.
I'm guessing this could be the numbered bookmarks feature. Try Shift-F11 to list all bookmarks or Ctrl-F11 to toggle it.

XML layout doesn't line break in android studio

After I updated my android studio , the XML formatting is ruined in the layout editor. Initially each attribute was on a separate line. Now however two or three attributes take a line .
I went into Settings->Editor->CodeStyle->XML and under the Layout Files region I have Wrap Attributes set as Wrap Always and Insert Line Break After First attribute is checked.
Yet the effect doesn't appear .
Any pointers?
I had occurred. Coz u r using Project Scheme . To fix this go Preferences>>Code Style>>XML on Scheme Combo Box , change to Default IDE
For Me, I overwrite project to Project Scheme( one that u don't like) with Default IDE. select setting icon and Copy to Project.
After all finished, Close preference pane with OK ,And then u are good to go.
Good Luck!
Just go to File->Settings->Keymap and search Reformat Code. You can find your shortcut to format your code and also you can remove and add new shortcuts for this.

Copy warning message when you hover over a WORD in Android Studio using Mac

Not sure if this question was already answered in the past but I was not able to find anything on it. I wanted to know if there is a possibility to immediately copy a warning that appears under some "words" in Android Studio?
Example:
Is there a Mac keyboard shortcut to copy that 'android.support.v4.app.ActionBarDrawerToggle' message?
This is an IntelliJ inherited problem. You can find a workaround here.
Basically, click on the error/warning in order to have the cursor on it. Then you will find the same message in the message bar on the bottom. Right-click and copy
Alt+click(left button of the mouse) on popup copies the whole text. Tested on android studio 3.6 windows 10.
I think it is possible to mark it with the mouse and while you still hold the mouse button down press cmd + c.... but in fact this is not a shortcut.

Where is the warnings screen option in Android Studio?

I want to see warnings of my code in Android Studio, But i am unable to find the option to display warnings view. In case of eclipse we can see the warnings in the "Problems" view.
Can anyone suggest me, how to view warnings in android studio?
If, on the toolbar, you click Analyze -> Inspect Code; then in the window that pops up select how much of your project you want to inspect (I usually do Whole Project, but you might want to select a specific module), then click okay.
Android Studio will work for a bit, then the inspection window will pop up from the bottom with a list of results, subdivided by inspection.
Build -> Make Project (Ctrl + F9) gives what we can get equivalent of Eclipse's “Problems” view on Android Studio
you can use F2 to next problems, see more here: Navigating to Next/Previous Error
GO to View-->Tool Windows-->Messages to view the warnings
Even i searched all the settings in Android Studio, but couldn't find a separate window for it.
The warnings are actually visible to the right end of a particular line as a small yellow marker and clicking on that show the warnings in the status bar below. The colors of them can be editted in the inspection options.
Hope this helps you.
The closest thing Android Studio/IntelliJ has to the Problems view in Eclipse is to use the Problems section of the Project tool window. With that open, navigate down to any classes that appear there and open them in the editor. Once in the editor, you can use F2 to jump between errors in the open file.
Unfortunately, IntelliJ's Problems tool window shows classes with errors nested by folder/package, so you have to expand several levels and it takes up a lot of screen real estate to see even one error. It also doesn't list the errors individually, forcing you to first open the problematic file and then use F2 to navigate to each one. I also had the problem that errors in files that weren't open, didn't show up there.
[opening warning screen in android studio
Click the warning icon as marked in the image.
Warning screen will open.
][click to see image] here

Visual Studio: Undo-redo of replace-action does not scroll editor window

I did some find-and-replace actions in my C++ code with visual studio:
only single find-and-replace actions (did not use “replace all”)
only one file affected (did not change multiple files at the same time)
thus, a very simple case!
Then I wanted to undo these changes. So I pressed ctrl-Z one time. This had the desired effect. The latest change (which was still visible in the current screen) was undone.
But I also wanted to undo the remaining changes. These changes where currently not visible on the screen. So I expected the editor to scroll there when pressing ctrl-Z.
But unfortunately the editor did not scroll to the position of the undo when I pressed ctrl-z.
The undo worked, however. I checked by scrolling to the position manually.
Then I tried it with redo. Same result: Redo worked, but the editor did not scroll to the position of the redo.
Finally I tried if this also happens when I undo-redo other types of changes (not made by the “find and replace” functionality).
Result: Undo-Redo worked correctly and also scrolled correctly!
Thus: It seems only changes by the “find and replace” functionality are affected by this problem.
Did you also have this problem and found a solution?
Please help me!
Regards Gerhard
I am having the same thing happen in Visual Studio Ultimate 2012 (Version 11.0.60610.01 Update 3).
It might sound like it's not that important, but it is really hurting the usability of this otherwise great IDE!
PS I've been using VS since the 90s, I still haven't found anything better. I wish MS would put macros back into VS, even if it's VBA (or Python)

Resources