Вопрос

In Android Studio, autocompleting a layout tag automatically inserts layout_width and layout_height attributes.

Typing this:

<Tex

and hitting Enter gives me this:

<TextView android:layout_width="" android:layout_height="" />

and locks my cursor in the layout_width attribute, destroying my typing flow and requiring me to escape and manually format the tag.

These attributes are required to be present, and Android Studio is smart enough to say as much, so I'm not even capable of making the mistake they're trying to correct. Is there a way to force autocomplete to insert only the tag name, without attributes?

Это было полезно?

Решение

File -> Settings -> Editor -> Smart Keys -> Uncheck Automatically insert required attributes

However, you should use space instead of pressing enter to do the autocomplete as pressing enter would close the tag (unchecking not to insert closing tag didn't work for me in this case).

If using space you can also uncheck Automatically start attribute depending on your needs. With this checked it will add a ="" to allow to start typing in an attribute.

enter image description here

Edit

For using the space key to autocomplete:

File -> Settings -> Editor -> Code Completion -> Check Insert selected variant by typing dot, space, etc.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top