Vincent D. Vincent D. - 3 months ago 8x
Android Question

Android Studio, where is the style to modify the line return on the "foreach" command

I can't figure how to Android Studio handle the styling of the

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.


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$) {

Type that template text in editor and 'Reformat Code', it wraps like this.

for ($i$:
     $data$) {

That's why live template works like that.

It's just a bug and you can use the temporary fix until bug fixed.