Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
673 views
in Technique[技术] by (71.8m points)

android-studio - 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?

(代码格式化的快捷方式是什么?)

  ask by Bhavesh Hirpara translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...