Android Studio中的代码格式快捷方式

本文翻译自:Code formatting shortcut in Android Studio

I have started developing with Android Studio . 我已经开始使用Android Studio进行开发了。 In Eclipse I was using Ctrl + Shift + F , but in Android Studio it does not work. 在Eclipse中我使用Ctrl + Shift + F ,但在Android Studio中它不起作用。 It will be different. 会有所不同。

How can I jump to any method in a .java file? 如何跳转到.java文件中的任何方法? I was using Ctrl + O in Eclipse. 我在Eclipse中使用Ctrl + O.

Is it available? 是可用的么? What is the shortcut for code formatting? 代码格式化的快捷方式是什么?


#1楼

参考:https://stackoom.com/question/17ZG7/Android-Studio中的代码格式快捷方式


#2楼

Windows: Ctrl + Alt + L Windows: Ctrl + Alt + L.

Linux: Ctrl + Shift + Alt + L Linux: Ctrl + Shift + Alt + L.

macOS: Option + Command + L macOS: Option + Command + L.

Reference: Key Commands and here are all of the commands for Windows/ Linux users and for Mac users . 参考: 键盘命令 ,以下是Windows / Linux用户Mac用户的所有命令。


As Rohit faced a problem in Ubuntu with the format code shortcut, this is due to the Ctrl + Alt + L key being used to lock the screen in Ubuntu. 由于Rohit在Ubuntu中遇到了格式代码快捷方式的问题,这是由于Ctrl + Alt + L键用于锁定Ubuntu中的屏幕。

I found that Ubuntu handles this keyboard shortcut first. 我发现Ubuntu首先处理这个键盘快捷键。 So you should bind the Ctrl + Alt + L keyboard shortcut to something else so that it doesn't conflict with Ubuntu. 因此,您应该将Ctrl + Alt + L键盘快捷键绑定到其他内容,以便它不会与Ubuntu冲突。

Steps 脚步

  1. Go to System ToolsSystem SettingsKeyboardShortcuts tab → SystemLock Screen . 进入系统工具系统设置键盘快捷方式选项卡→ 系统锁定屏幕

  2. Select the row New Accelerator... , then press any special key with the Alpha key (eg Shift + L ). 选择New Accelerator ...行,然后按任意特殊键和Alpha键(例如Shift + L )。 You should've successfully changed the keyboard shortcut. 您应该已成功更改键盘快捷键。

  3. Check if the keyboard shortcut now works in Android Studio. 检查键盘快捷键现在是否可以在Android Studio中使用。

Alternative method 替代方法

Ctrl + Alt + Shift + L (to show a dialog) Ctrl + Alt + Shift + L (显示对话框)


You can also use Eclipse shortcuts. 您还可以使用Eclipse快捷方式。

  • Windows and Linux: Go to menu FileSettingsKeymap Windows和Linux:转到菜单文件设置键盘映射
  • macOS: Go to menu PreferencesKeymap and choose Eclipse from the drop-down menu. macOS:转到菜单PreferencesKeymap,然后从下拉菜单中选择Eclipse。

Using MenuBar 使用MenuBar

  • Select code which you want to reformat 选择要重新格式化的代码
  • Click on Code in the menu bar and select Reformat Code as shown in the image below: 单击菜单栏中的“代码” ,然后选择“ 重新格式化代码” ,如下图所示:

    在此输入图像描述

In Android studio 3.5, there is problem with rearranging the xml code, it also rearrange the views as well, so need to use these settings first. 在Android studio 3.5中,重新排列xml代码存在问题,它也会重新排列视图,因此需要先使用这些设置。

Settings -> Editor -> Code Style -> XML-> Set From -> Predefined Style > Android. 设置 - >编辑器 - >代码样式 - > XML->设置自 - >预定义样式> Android。


#3楼

Check Keyboard Commands given in the Android Studio Tips & Trick documentation: 检查Android Studio Tips&Trick文档中给出的键盘命令

在此输入图像描述


#4楼

You can also use Eclipse's keyboard shortcuts: just go to menu Preferenceskeymap and choose Eclipse from the dropdown menu. 您还可以使用Eclipse的键盘快捷键:只需转到菜单Preferenceskeymap,然后从下拉菜单中选择Eclipse


The actual path is: menu FileSettingsKeymap (under IDE settings) 实际路径是:菜单文件设置 →键映射 (在IDE设置下)


#5楼

For formatting code in Android Studio on Linux you could instead use Ctrl + Alt + Super + L . 要在Linux上安装Android Studio中的代码,您可以改为使用Ctrl + Alt + Super + L. You could use this and avoid having to change the system shortcut. 您可以使用此功能,避免更改系统快捷方式。 ( Super key is the Windows icon key besides the Alt key). 超级键是除Alt键之外的Windows图标键)。


#6楼

The best key where you can find all commands in Eclipse is Ctrl + Shift + L . 在Eclipse中可以找到所有命令的最佳键是Ctrl + Shift + L.

By pressing this you can get all the commands in Eclipse. 通过按此按钮,您可以获得Eclipse中的所有命令。

One important is Ctrl + Shift + O to import and un-import useless imports. 一个重要的是Ctrl + Shift + O来导入和取消导入无用的导入。

发布了0 篇原创文章 · 获赞 8 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/asdfgh0077/article/details/105448088
今日推荐