Android Studio代码格式问题

cha*_*ura 1 android code-formatting android-studio

我正在使用Android Studio并在格式化代码时遇到问题.如果有一个语句分成多行,我需要将其格式化为单行语句,我不能使用(Ctrl + Alt + L).代码未使用该快捷方式格式化为单行.

我尝试将右边距(设置 - >编辑器 - >代码样式)的值更改为更高的数字,但这也不起作用.

如何将代码格式化为单行?

谢谢.

Car*_*res 8

首先去Preferences > Editor > Code Style并设置Right margin (columns)140(或更高)

现在去Preferences > Editor > Code Style > Java > Wrapping and Braces > Keep when reformattinguncheck复选框Line Breaks,这样格式化将删除不必要的换行符,使语句适应尽可能在一个单行

还建议,在Preferences > Editor > Code Style > Java > Wrapping and Braces确保check复选框时Ensure right margin is not exceeded,格式化程序将在语句超出最大右边距时强制换行.