简体   繁体   English

如何从Android Studio中片段的XML布局导航到相应的java类?

[英]How to navigate to the corresponding java class from XML layout for fragments in Android Studio?

Suppose that I am in a layout file named "main.xml" and its corresponding fragment java class is "MainFragment.java".假设我在一个名为“main.xml”的布局文件中,它对应的片段java类是“MainFragment.java”。

Is there any shortcut to go to "MainFragment.java" from the "main.xml" or any other way?是否有任何快捷方式可以从“main.xml”或任何其他方式转到“MainFragment.java”?

It will be helpful to navigate around xml and java classes quickly when there are a lot of java classes and xml files in the project.当项目中有很多 java 类和 xml 文件时,快速浏览 xml 和 java 类会很有帮助。

Note: For activity, there is a “C” symbol found in the top-left corner of the layout XML file.注意:对于活动,布局 XML 文件的左上角有一个“C”符号。 When we click that "C" symbol it will take us to corresponding java class in which the xml file is used.当我们单击“C”符号时,它会将我们带到使用 xml 文件的相应 java 类。 But for fragments, there is nothing available.但是对于碎片来说,没有什么可用的。

使用'Related Symbol' (Navigate -> Related Symbol...) 在windows下,按ctrl+alt+home,可以在activity/fragment和对应的布局文件之间切换

You could right click on the file main.xml and in the options menu click Find Usages .您可以右键单击文件main.xml并在选项菜单中单击Find Usages You can then see all the places where main.xml is used.然后您可以看到使用main.xml所有地方。

Add to your root layout添加到您的根布局

tools:context="your_screen_here"

Then you can navigate directly by clicking to this blue button on left side (I'm using material theme, your icon and color can be different)然后您可以通过单击左侧的这个蓝色按钮直接导航(我使用的是材质主题,您的图标和颜色可以不同)

If I understand your question then you must be looking for short-cut keys for navigating around all *.java and *.xml files in Android Studio IDE editor.如果我理解您的问题,那么您一定是在寻找用于在 Android Studio IDE 编辑器中浏览所有 *.java 和 *.xml 文件的快捷键。

Here are few short-cut keys I use on regular basis which might help you out!这里有一些我经常使用的快捷键,可能会对你有所帮助!

  1. To navigate around any class files from any opened tabs -> ctrl + N从任何打开的选项卡浏览任何类文件 -> ctrl + N
  2. To navigate around any files (including class, xml, etc.) -> ctrl + Shift + N浏览任何文件(包括类、xml 等)-> ctrl + Shift + N
  3. To navigate through various opened tabs -> Alt + Legt/Right-Arrow Keys浏览各种打开的选项卡 -> Alt + Legt/Right-Arrow Keys

Hope it would help you out!希望能帮到你!

Cheers!干杯!

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM