Android studio Kotlin put function call parameters on the same line

Viewed 925

Android Studio automatically formats method calls this way:

HelperFunctions.showProperty(
    layoutInflater,
    propertyInsertPoint,
    getString(R.string.height),
    resident.height.toString()
)

I would like it to automatically format them this way:

    HelperFunctions.showProperty(layoutInflater, propertyInsertPoint, getString(R.string.height), resident.height.toString())

How can I achieve this?

1 Answers

Android Studio uses your line length settings — from Settings > Editor > Code Style, .editorconfig, etc. — to decide if it needs to add line breaks when reformatting. However, by default, even if you increase the line length setting, Android Studio will not remove line breaks, even if it had added them previously.

That is controlled by "Keep when reformatting > Line breaks" in the code style for your particular language, such as Kotlin:

Android Studio Kotlin Code Style Settings

If you uncheck that, then you are allowing Android Studio to remove line breaks where possible. That may have unintended side effects, with Studio removing line breaks in places that you had not anticipated.

Related