如何在Android Studio代码编辑器中设置最大行长? [英] How to set max line length in Android Studio code editor?
问题描述
如何为Android Studio的代码编辑器设置最大长度,或者可以设置自动换行?
How can I set a maximum length for Android Studio's code editor, or may be set a word wrap?
在我的Android Studio中,无论我在单行中键入多长时间,它都不会自动转到下一行,而是会出现水平滚动条.
In my Android Studio, no matter how long a statement I type on a single line, it never automatically goes to the next line, but rather a horizontal scroll bar appears.
When I autoformat using the Ctrl
+Alt
+L
(reference), nothing happens.
我的SO或Google搜索找到了很多有关Eclipse的资料,但没有有关Android Studio的资料.
My SO or Google search found a lot of material on this for Eclipse, but not for Android Studio.
推荐答案
如果您需要不需要包装,
但实际上,将一条长线刹车成您需要的几条线:
If you need not a soft wrap,
but actually, brake one long line onto several lines you need:
转到偏好设置"->编辑器"->代码样式"->"Java/科特琳"->包装和花括号(标签)"->选中确保不超出右边距"
现在尝试重新格式化您的代码:
按
Mac上的OPTION(ALT)+ CMD + L
(或PC上的CTRL + ALT + L)
Now try to reformat your code:
press
OPTION (ALT) + CMD + L on your Mac
(or CTRL + ALT + L on PC)
编辑13.02.19
如评论中所述,此选项在Kotlin的设置中似乎不可用.
但是,有一种解决方法可以手动添加.
这是使其工作所需的条件:
As noted in comments this option seems not available in settings for Kotlin.
However, there is a workaround to manually add it.
Here is what it takes to make it work:
-
导出设置方案.
Export the settings scheme.
打开保存的xml文件.
Open saved xml file.
手动添加WRAP_LONG_LINES设置:
Add the WRAP_LONG_LINES setting manually:
<codeStyleSettings language="kotlin">
...
<option name="WRAP_LONG_LINES" value="true" />
</codeStyleSettings>
这篇关于如何在Android Studio代码编辑器中设置最大行长?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!