简体   繁体   中英

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".

Is there any shortcut to go to "MainFragment.java" from the "main.xml" or any other way?

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.

Note: For activity, there is a “C” symbol found in the top-left corner of the layout XML file. When we click that "C" symbol it will take us to corresponding java class in which the xml file is used. 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 . You can then see all the places where main.xml is used.

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.

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
  2. To navigate around any files (including class, xml, etc.) -> ctrl + Shift + N
  3. To navigate through various opened tabs -> Alt + Legt/Right-Arrow Keys

Hope it would help you out!

Cheers!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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