51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 1366|回复: 0
打印 上一主题 下一主题

【转载】Android Studio 使用技巧(6)

[复制链接]
  • TA的每日心情
    擦汗
    8 小时前
  • 签到天数: 1047 天

    连续签到: 5 天

    [LV.10]测试总司令

    跳转到指定楼层
    1#
    发表于 2016-4-28 15:06:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

    转载请注明本文出自Cym的博客(http://blog.csdn.net/cym492224103),谢谢支持!

    About Keymaps

    Android Studio provides different keymaps (the mapping between shortcut keys and an action). You can see which keymap you are using in Settings->Keymap.

    It wouldn’t be practical to list the shortcuts for every keymap so the following will be used:

    • Windows: Default
    • Linux: Default
    • OSX: Mac OSX 10.5+

    Refactor This

    This is a shortcut to contextually show all the available refactorings for the current selection. This list is keyboard searchable and you can use the number on the left for a quicker access

    Shortcut (Menu):

    • Mac: Ctrl+T
    • Windows/Linux: Ctrl+Alt+Shift+T

    Navigate to parent

    If you are in a method that is overriding a parent class (e.g. Activity#onCreate()), this will navigate to the parent implementation.

    If you are on the class name, it will navigate to the parent class.

    Shortcut :

    • Mac: Cmd+U
    • Windows/Linux: Ctrl+U

    Recently Changed Files

    This is a variation of the “Recents” popup that lists files that were recently modified locally. It is sorted in order of modification (most recently edited on top). A nice bonus is that you can type to filter the list.

    Shortcut (Menu):

    • Mac: Cmd+Shift+E
    • Windows/Linux: Ctrl+Shift+E

    Jump to Last Tool Window

    Sometimes, you return to the editor from a panel but find yourself having to go back to this panel. e.g. browsing find usages. With this, you can go back to a panel without your mouse.

    Shortcut: F12 (might interfere with the OS’s default keybindings)


    Related File

    It helps you navigate between your layout and your activity/fragment with ease. There is also a shortcut in the gutter next to the class name and one at the top of the layout file.

    Shortcut (Menu):

    • Mac: Ctrl+Cmd+Up
    • Windows/Linux: Ctrl+Alt+Home

    Extract Variable

    This is a shortcut to extract a variable without going through the refactoring menu.

    This is very useful when you are generating code on the fly as you can avoid typing the variable declaration and go straight to the value. The IDE will then generate the declaration and it will come up with some suggestions on how to name the variable.

    Additional tip:

    • If you want to change the declaration type to something more generic (e.g. List instead of ArrayList), you can press Shift+Tab and it will give you a list of valid types.

    Shortcut (Menu):

    • Mac: Cmd+Alt+V
    • Windows/Linux: Ctrl+Alt+V

    Extract Parameter

    This is a shortcut to extract a parameter without going through the refactoring menu.

    This thing is useful when you realize that a method could be generified by extracting one part as a parameter. The way it works is that it will take the current value, make it a parameter and copy the old value as the parameter for each caller.

    Additional tip:

    • You can also keep the original method and have it delegate to the new one by ticking the “delegate” box.

    Shortcut (Menu):

    • Mac: Cmd+Alt+P
    • Windows/Linux: Ctrl+Alt+P

    Extract Method

    Following in my streak of extract refactoring, here is the one to extract a code block in a new method.

    This thing is extremely useful. Whenever you encounter a method that is starting to become a bit complex, you can use this to safely extract a portion in another method. I say safely because the IDE won’t make a silly copy-paste mistake like we might do.

    Additional tip:

    • Once you are in the extractin dialog, you can change the visibility of the method and the parameter names.

    Shortcut (Menu):

    • Mac: Cmd+Alt+M
    • Windows/Linux: Ctrl+Alt+M

    Inline

    So you have gone a bit crazy with extraction and now you have too much stuff? You can do the reverse operation, which is called “inline”.

    This will work with methods, fields, parameters and variables.

    Shortcut:

    • Mac: Cmd+Alt+N
    • Windows/Linux: Ctrl+Alt+M

    Rename

    With this, you can rename a variable, field, method, class and event package. This will, of course, make sure that the renaming makes sense in the context of your app, it won’t simply do a find and replace in all files!

    Additional Tip:

    • If you can’t remember this shortcut, you can always invoke the quick fix shortcut and it will always include the rename refactoring.

    Shortcut: Shift+F6


    Pull Up / Push Down

    When we talk about pulling something up, we mean that we will take something in the current class (usually a method or a field) and send it to the parent class or interface.

    If the parent is a class, the content will be moved. If the parent is an interface, it will declare the method as part of the interface, keep the method in your class and add the @override annotation.

    When we talk about pushing members down, that is exactly the opposite operation, we are sending content from the parent class/interface in the child class.

    Shortcut:

    • Mac: Ctrl+T and choose pull members up / push members down
    • Windows/Linux: Ctrl+Alt+Shift+T and choose pull members up / push members down
    • 本文出自Cym的博客(http://blog.csdn.net/cym492224103

    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-11-15 17:47 , Processed in 0.061133 second(s), 22 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表