eclipse Intellij Idea / Android Studio 中的 Android 代码风格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16710367/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Code Style in Intellij Idea / Android Studio
提问by Ivan Morgillo
Before Android Studio, I was using android-formatting.xmlas Code Style in Eclipse.
在 Android Studio 之前,我在 Eclipse 中使用android-formatting.xml作为代码样式。
How can I setup Android Studio / Intellij Idea to format code as in Eclipse?
如何设置 Android Studio/Intellij Idea 以像在 Eclipse 中一样格式化代码?
UPDATE
更新
I tried Eclipse Code Formatter plugin. It seems to work, but you cannot edit any setting at all. My team prefers 120 columns instead of 100.
我尝试了 Eclipse Code Formatter 插件。它似乎有效,但您根本无法编辑任何设置。我的团队更喜欢 120 列而不是 100 列。
I tried @CrossleSong answer too. It's a bit tricky, but more powerful. You can save this
我也试过@CrossleSong 的回答。这有点棘手,但更强大。你可以保存这个
as Android.xmland copy it to AndroidStudio/Intellij codestyles folder: for me is
作为Android.xml并将其复制到 AndroidStudio/Intellij codestyles 文件夹:对我来说是
~/Library/Preferences/AndroidStudioPreview/codestyles
~/Library/Preferences/AndroidStudioPreview/codestyles
Now you can select Android as Code Style in Android Studio Preferences.
现在您可以在 Android Studio Preferences 中选择 Android 作为 Code Style。
采纳答案by Crossle Song
You can download the developmentrepo from Android source. The development/ide/intellij
folder includes code style, templates...
您可以从 Android 源下载开发存储库。该development/ide/intellij
文件夹包括代码样式、模板...
回答by Ayaz Alifov
Instructions to use Eclipse XML formatter in Android Studio:
在 Android Studio 中使用 Eclipse XML 格式化程序的说明:
- File -> Settings -> Plugins
- click 'Browse repositories' button, enter 'Eclipse Code Formatter' in the search field and install the plugin.
- Restart Android Studio.
- File -> Settings -> Other Settings -> Eclipse Code Formatter (if you cannot find it, then use search field for that)
- select 'Use the Eclipse code formatter', browse your xml style file and press OK button to close the Settings.
- 文件 -> 设置 -> 插件
- 单击“浏览存储库”按钮,在搜索字段中输入“Eclipse 代码格式化程序”并安装插件。
- 重启安卓工作室。
- 文件 -> 设置 -> 其他设置 -> Eclipse 代码格式化程序(如果找不到,请使用搜索字段)
- 选择“使用 Eclipse 代码格式化程序”,浏览您的 xml 样式文件,然后按 OK 按钮关闭设置。
I hope I wrote instructions clear. Let me know in case you didn't understand.
我希望我写的说明清楚。如果你不明白,请告诉我。
回答by CrazyCoder
You can use the third-party Eclipse Code Formatterplug-in for IntelliJ IDEA / Android Studio.
您可以使用IntelliJ IDEA/Android Studio的第三方Eclipse Code Formatter插件。
回答by Shobhit Puri
For Android Studio 1.2.2
and above:
对于Android Studio 1.2.2
及以上:
What didn't work for me:
什么对我不起作用:
Thanks for the question. There are good answers and hints here but for my case where I updated to Android Studio 1.2.2, it didn't work right out of the box. Some answers and blogssuggested that after downloading the xml
file,
谢谢你的提问。这里有很好的答案和提示,但对于我更新到 Android Studio 1.2.2 的情况,它无法立即使用。一些答案和博客建议下载xml
文件后,
- Save the
xml
file to~/Library/Preferences/AndroidStudio/codestyles
. - Then restart
AndroidStudio
Go to
Android Studio -> Preferences -> Code Style -> Java
and fromScheme
dropdown select the scheme name and save.However when I put the xml file inside
~/Library/Preferences/AndroidStudio/codestyles/
folder it didn't show my scheme name in theScheme
dropdown to select from.
- 将
xml
文件保存到~/Library/Preferences/AndroidStudio/codestyles
. - 然后重启
AndroidStudio
转到
Android Studio -> Preferences -> Code Style -> Java
和从Scheme
下拉列表中选择方案名称并保存。但是,当我将 xml 文件放入
~/Library/Preferences/AndroidStudio/codestyles/
文件夹时,它没有在Scheme
下拉列表中显示我的方案名称以供选择。
What worked for me:
什么对我有用:
After I updated Android Studio to latest version, under ~/Library/Preferences/
in mac, I had two folders: AndroidStudio
and AndroidStudio1.2
. For importing the AndroidStyle.xmlcode style file in the updated Android studio, I had to create a folder named codestyles
inside ~/Library/Preferences/AndroidStudio1.2/
folder, since none existed. Then I saved the xml
file in there and followed the above procedure. Just saving the file solely in .../AndroidStudio/codestyles
folder didn't work for me.
在我将 Android Studio 更新到最新版本后,~/Library/Preferences/
在 mac 下,我有两个文件夹:AndroidStudio
和AndroidStudio1.2
. 为了在更新的 Android Studio 中导入AndroidStyle.xml代码样式文件,我必须创建一个名为codestyles
inside ~/Library/Preferences/AndroidStudio1.2/
folder 的文件夹,因为不存在。然后我将xml
文件保存在那里并按照上述程序进行操作。仅将文件单独保存在文件.../AndroidStudio/codestyles
夹中对我不起作用。
Hope it helps someone some day.
希望有一天它可以帮助某人。