简体   繁体   English

是否可以在 Android Studio 中永久保留我的代码样式偏好

[英]Is it possible to keep my code style preferences permanent in Android Studio

To set your own code style preferences in Android Studio, the following steps would be followed:要在 Android Studio 中设置您自己的代码样式首选项,请执行以下步骤:

File > Settings (Ctrl + Alt + S) > Editor > Code Style > Java.

or或者

File > Settings (Ctrl + Alt + S) > Editor > Code Style > Kotlin.

The scheme choices would be the following:方案选择如下:

Andriod Studio 编辑器代码风格方案

However, when I do restart android studio these changes are not saved.但是,当我重新启动 android studio 时,这些更改不会保存。

There have been times when I have had to Invalidate the Caches and Restart Android Studio.有时我不得不使缓存无效并重新启动 Android Studio。 Would this have result in these preferences being lost?这会导致这些偏好丢失吗? As my understanding of the clearing, the cache is code changes.正如我对清除的理解,缓存是代码更改。

If you navigate to app >.idea > codeStyles folder you can see the codeStyleConfig and the Project code style, the codeStyleConfig lets the ide know which code style you have set whilst the Project file is an xml representation of the code style you defined in the settings.如果您导航到app >.idea > codeStyles文件夹,您可以看到codeStyleConfigProject代码样式, codeStyleConfig让 ide 知道您设置了哪种代码样式,而Project文件是您在设置。

I'm not sure why they are being cleared when restarting but you can add exceptions to these files in your gitignore file so that they can be committed, that way they should remain consistent even if you check the project out on another computer.我不确定为什么在重新启动时它们会被清除,但是您可以在 gitignore 文件中为这些文件添加例外,以便可以提交它们,这样即使您在另一台计算机上签出项目,它们也应该保持一致。

# IDEA/Android Studio ignore exceptions
!/.idea/codeStyles

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM