简体   繁体   English

如何找到在 Android Studio 中使用方法或变量的位置(快捷方式)

[英]How can i find where a method or a variable is used in Android Studio (shortcut)

I know how to find the source by using ctrl + left click on a method, for example, but what if I want to find where this method is used?例如,我知道如何通过使用ctrl + 左键单击某个方法来查找源,但是如果我想查找使用此方法的位置怎么办? I'm using Windows 7.我正在使用 Windows 7。

Let's suppose I have the following method:假设我有以下方法:

class A {
    public int sum(int a, int b) {
        return a+b;
    }
}

and I am using this method in我正在使用这种方法

class B {
    ...
    a.sum(c, d);
    ...
}

and I want to find where I used sum while I was in class A .我想找到我在A班时使用sum地方。

PS: I'm new to Android studio (started using it about a month ago). PS:我是 Android Studio 的新手(大约一个月前开始使用它)。

In Android Studio, highlight the method and either right click > Find usages or use the Alt + F7 shortcut.在 Android Studio 中,突出显示该方法,然后右键单击 > 查找用法或使用Alt + F7快捷方式。

Edit: Ctrl + left click on a method is useful for finding where that method was initially declared编辑: Ctrl +左键单击某个方法对于查找该方法最初声明的位置很有用

For Ubuntu users:对于 Ubuntu 用户:

For me Alt + F7 has not worked, so I've solved the conflict by going to the对我来说Alt + F7没有用,所以我通过转到

Ubuntu System settings-> keyboard -> shortcuts

and changing Alt + F7 in there with another combination.并使用另一种组合更改Alt + F7

And now it's working ))现在它正在工作))

只需单击方法或变量,任何用法都会突出显示,在代码右侧的滚动条上,您会看到灰色条出现,这些是当前突出显示(或单击)的变量或方法在您的代码中的用法代码。

To find all uses of a variable or method in Android Studio you can use要在 Android Studio 中查找变量或方法的所有用途,您可以使用

  1. ctrl+shift+F7(window/Ubuntu) ctrl+shift+F7(窗口/Ubuntu)
  2. after that for navigation purpose you can use F3之后出于导航目的,您可以使用 F3

Here are different key shortcuts for displaying method or variable usage.以下是用于显示方法或变量用法的不同快捷键。 The keymaps with F14 in them were added by me;里面有F14的keymap是我自己加的; the others are default.其他都是默认的。 For Windows (and Linux?), replace the key with Ctrl (I think).对于 Windows(和 Linux?),将键替换为Ctrl (我认为)。 Find Usages shows them in a dedicated window in Android Studio (the solution in other answers), while Show Usages puts them in a popup (second image below). Find Usages 将它们显示在 Android Studio 的专用窗口中(其他答案中的解决方案),而 Show Usages 将它们放在弹出窗口中(下图第二张)。

我的 Android Studio 偏好设置

用法弹出窗口(<kbd>⌘</kbd><kbd>option</kbd><kbd>F7</kbd>

使用 [Ctrl+b] 或 [Ctrl+Alt+b] 导航到方法的原点或变量的清除和实现

Ubuntu is Ctrl+Alt+7 or Ctrl+b to show the usage of the class. Ubuntu 是Ctrl+Alt+7Ctrl+b来显示类的用法。 Ctrl+Alt+F7 is not work. Ctrl+Alt+F7不起作用。

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

相关问题 在Android Studio中哪里可以找到Android虚拟设备? - Where can I find Android virtual device in Android Studio? 我在哪里可以找到android studio中的数据库和表记录? - where can i find database and table records in android studio? 如何在Eclipse中查找某个变量/方法的所有出现? 即相当于Android Studio的“ cmd + b” - How to find all occurrences of a certain variable/method in Eclipse? i.e the equivalent of “cmd + b” of Android Studio 如何找到Java项目中使用方法的位置 - How to find where a method is used in Java project 如何使用android studio中的onClick方法设置在另一个类中定义的变量? - How can I set a variable that was defined in another class with the onClick method in android studio? 声明的方式和位置,以便可以由Android Studio中的两种方法使用 - How and Where can a declaration go so it can be used by two methods in Android Studio 在类或方法中最佳放置变量的位置(Android Studio) - Where to best put a variable, in the class or in the method (Android Studio) 在哪里可以找到版本变量的值? - Where can I find the value of version variable? Android-如何找出当前线程的创建位置? - Android - How can I find out where the current thread was created? 如何在android studio中找到数组中项目的编号? - how can I find the number of an item in an array in android studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM