[英]Android studio 3.5 refactor issue
I've just updated to Android Studio 3.5 and now when I try to refactor the file AndroidManifest.xml
, all my app permissions are moved to the bottom of the file.我刚刚更新到 Android Studio 3.5,现在当我尝试重构文件AndroidManifest.xml
,我的所有应用程序权限都移到文件底部。
Has anyone else faced this issue?有没有其他人遇到过这个问题? Is there any solution for this?有什么解决办法吗?
Before refactor:重构前:
After refactor:重构后:
It is applicable to my all project files.它适用于我的所有项目文件。
You just need to set xml layout for Android applications from the settings.您只需要从设置中为 Android 应用程序设置 xml 布局。
Follow this steps:请按照以下步骤操作:
1. Go to Android Studio > Preferences . 1.转到Android Studio >首选项。 For Windows, go to File > Settings .对于 Windows,转到文件>设置。
2. Search for xml in search bar. 2.在搜索栏中搜索xml 。
3. Under code style section, select xml tab. 3.在代码样式部分下,选择xml选项卡。
4. In the top right corner, click on set from... and under predefined style , select Android 4.在右上角,单击set from...并在预定义样式下,选择Android
5. Click on Apply and try to refactor. 5.单击 Apply 并尝试重构。
Reset the appropriate Android code style as follows.如下重置相应的 Android 代码样式。
For Windows Only仅适用于Windows
Step1: Click on the file menu.第一步:点击文件菜单。
Step2: Navigate to Setting .步骤2:导航到设置。
Step3: Find Editor in the Left Panel**.第三步:在左侧面板中找到编辑器**。
Step4: Find Code Style in the Sub Menu of Editor. Step4:在编辑器的子菜单中找到代码样式。
Step5: Click on XML in the Sub Menu of Code Style.第五步:在代码样式的子菜单中点击XML 。
Step6: Click on Set from in Top right corner of Right panel.第六步:点击右侧面板右上角的设置。
Step7: Select Predefined Style .第七步:选择预定义样式。
Step8: Select Android .第八步:选择安卓。
Step9: Click OK .第九步:点击确定。
For macOS Only仅适用于macOS
Step1: Click on the Android Studio menu. Step1:点击Android Studio菜单。
Step2: Navigate to Preferences .步骤 2:导航到Preferences 。
Step3: Find Editor in the Left Panel**.第三步:在左侧面板中找到编辑器**。
Step4: Find Code Style in the Sub Menu of Editor. Step4:在编辑器的子菜单中找到代码样式。
Step5: Click on XML in the Sub Menu of Code Style.第五步:在代码样式的子菜单中点击XML 。
Step6: Click on Set from in Top right corner of Right panel.第六步:点击右侧面板右上角的设置。
Step7: Select Predefined Style .第七步:选择预定义样式。
Step8: Select Android .第八步:选择安卓。
Step9: Click OK .第九步:点击确定。
Just adding more details .只是添加更多细节。
This is a known issue with android studio from Android Studio 3.5 Canary 8 .这是 Android Studio 3.5 Canary 8 中 android studio 的一个已知问题。 It should get fixed in next version as this turned out to affect large number of developers .它应该在下一个版本中得到修复,因为这会影响大量开发人员。
You can see status of the bug here您可以在此处查看错误状态
Also the solution is解决方法也是
Broken XML code style损坏的 XML 代码样式
When editing XML code, the IDE might apply an incorrect code style when you select Code > Reformat Code from the menu bar.编辑 XML 代码时,当您从菜单栏中选择代码 > 重新格式化代码时,IDE 可能会应用不正确的代码样式。 To fix this issue, reset the appropriate Android code style as follows:要解决此问题,请按如下方式重置相应的 Android 代码样式:
- Open the Settings window by clicking File > Settings (on macOS, Android Studio > Preferences).单击文件 > 设置(在 macOS 上,Android Studio > 首选项)打开“设置”窗口。
- In the left panel, click Editor > Code Style > XML.在左侧面板中,单击编辑器 > 代码样式 > XML。
- Near the top-right corner of the right panel, select Set from > Predefined Style > Android在右侧面板的右上角附近,选择设置自 > 预定义样式 > Android
- Click OK.单击确定。
Which is found here -> Known issues with Android Studio and Android Gradle Plugin可在此处找到 -> Android Studio 和 Android Gradle 插件的已知问题
Edit: This is now fixed in Android studio version 3.5.2编辑:这现在在 Android Studio 3.5.2版中得到修复
If you have a custom code style defined, you have to specify a type for each rule: tag or attribute.如果定义了自定义代码样式,则必须为每个规则指定类型:标记或属性。
It seems like after the update, if you do not specify a type, the rules will be applied to both.好像更新后,如果不指定类型,规则将同时应用于两者。 Not sure if it is a bug, but that's how i fixed.不确定这是否是一个错误,但我就是这样修复的。
This does not work on 3.5这不适用于 3.5
After adding the attribute type to each rule, it worked将属性类型添加到每个规则后,它起作用了
Please follow these steps for Windows version of "Android Studio 3.5"请按照以下步骤操作 Windows 版本的“Android Studio 3.5”
1: Click on the File in the Menu. 1:点击菜单中的文件。
2: Go to Settings. 2:进入设置。
3: Click on Editor. 3:点击编辑器。
4: Click on Code Style 4:点击代码样式
5: Click on XML. 5:点击XML。
6: Click on "Set from..." in top-right corner. 6:点击右上角的“设置自...”。
7: Select Predefined Style. 7:选择预定义样式。
8: Select Android. 8:选择安卓。
9: Click OK. 9:点击确定。
When editing XML code, the IDE might apply an incorrect code style when you select Code > Reformat Code from the menu bar.编辑 XML 代码时,当您从菜单栏中选择代码 > 重新格式化代码时,IDE 可能会应用不正确的代码样式。 To fix this issue, reset the appropriate Android code style as follows:要解决此问题,请按如下方式重置相应的 Android 代码样式:
For anyone searching this for Android Studio 4+ :对于在 Android Studio 4+ 中搜索此内容的任何人:
File -> Setting -> Editor -> Code Style -> XML -> Arrangement ->
If you don't have any custom code style for your IDE 如果您的IDE没有任何自定义代码样式
File | 档案| Settings | 设置| Editor | 编辑器 Code Style | 代码样式| XML | XML | Arrangement 安排
Find gear(settings) icon in the top, click it then press "restore defaults". 在顶部找到齿轮(设置)图标,单击它,然后按“恢复默认设置”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.