Android Studio - Hotkey for navigating to xml declaration is instead navigating to R file
Asked Answered
O

7

6

Original Title: What is the hotkey, if any, for navigating to layout file or a resource's value?

(This question didn't really describe the issue at hand. And as you can imagine, it attracted some obvious answers. My apologies, this is the first question I've posted.)

I'm using Android Studio version 1.1.0 on Mac.

Say I have a line of code similar to this:

    setContentView(R.layout.layout_main);

In Eclipse, I could simply use 'command + click' on the resource ID and it would navigate to the respective xml file then highlight the string, view, or color declaration. However, doing so in Android Studio navigates me to the declaration within the R file, which is utterly useless.

Is there a separate hotkey that I missed, or a separate event/action I could bind the current hotkey to, that would cause AS to operate more like Eclipse in this manner?

EDIT

After a couple answers -- which were correct according to the original question -- and some experimentation (created a fresh new project - I feel silly for not doing that earlier), it seems Android Studio should in fact navigate to the exact line in the xml where the View, String, or Color resource is declared, just like Eclipse does. However in my situation, it isn't for some odd reason.

This is merely speculation, but I suppose the culprit could be one or a combination of three things:

  1. The project I was working on - It was recently migrated from an Eclipse project to Android Studio project. This seems to be the most likely since the issue persists after updating items 2 and 3.
  2. The JDK version - When I created the new project, AS complained that my compiler was outdated (was running 1.6, upgraded to 1.7).
  3. Target SDK - the reason I was prompted to upgrade the JDK.
Ozzy answered 16/3, 2015 at 16:56 Comment(4)
cmd - shift - n > then start to type the name of file and the list will filter downLongwinded
I think you mean cmd - shift - o. The hotkey you provided does absolutely nothing. Nevertheless, this doesn't solve my problem. I'm not trying to find the file, I already know my string is in strings.xml. What I'm trying to do is navigate straight to the line in the xml where the value or view is declared, like Eclipse does.Ozzy
Did you managed to find a workaround for this issue?Foreknowledge
@Foreknowledge I've resolved the issue. Read my answer below if you are still interested.Ozzy
R
5

CTRL + B should do it. Otherwise you can create your own shortcuts.

Roughhouse answered 16/3, 2015 at 17:12 Comment(2)
This hotkey still takes me to the R file. I'd make my own shortcut, but I do not know the name of the action to bind to, that is, if there even is an alternate action that can do this besides 'Go to Declaration' and 'Go to Implementation'.Ozzy
Your reply did answer the original question, however I had poorly phrased it, as it did not describe the real issue at hand. I'm still upvoting though, since it did help identify that the behavior I encountered was abnormal. Please take a look at my edited description and feel free to provide another answer :)Ozzy
S
4

In Android Studio you can just click "Shift" button twice. You can either open java Class, xml layout, gradle files, android manifest and almost everything. hope it helps.

-cheers / happy codings.

Soria answered 4/9, 2015 at 1:38 Comment(1)
This way i found a layout resource from the 3rd party lib non-accessible otherwise. Thanks)Seduce
B
2

I am using Mac (OS X Yosemite).

Holding down the Command + Tapping the id of an Item is taking me to the xml right now.

But another shortcut is point your cursor over the ID and click Command + B

If you want to go to the class file from the xml then click Command + O I can share some additional shortcuts: Command + E for recent files.

If you want to search from the recent list Then click "Shift" twice

Benia answered 16/3, 2015 at 17:20 Comment(0)
A
2

in windows Ctrl+B switched between Design Mode and Text Mode.
Ctrl + leftClick moves to declaration

Agnate answered 16/3, 2015 at 20:17 Comment(3)
Your reply did answer the original question, however I had poorly phrased it, as it did not describe the real issue at hand. I'm still upvoting though, since it did help identify that the behavior I encountered was abnormal. Please take a look at my edited description and feel free to provide another answer :)Ozzy
Okay, so if I go into File>Settings>KeyMap i have the default configuration selected. I assume you have the one for Mac. If you expand Main menu>Navigate you will find declaration; which may or may not have keys assigned to it. You can right click on it an select 'Add keyboard shortcut' and select whichever shortcut you'd prefer. Apparently Meta+B is a default Mac shortcutRoughhouse
Thank you Catalina, I have found the Declaration/Implementation actions. They are set to the default binding, (Cmd/Ctrl + click, Cmd/Ctrl + B), but these shortcuts are still navigating me to the R file declaration instead. If I create a new project though, they work as expected. So my guess is it has something to do with the project I was working with, as it was once an Eclipse project that was migrated to an Android Studio project.Ozzy
C
1

Command + B works for Mac

For Windows, I am not so sure for I am not using windows.
Chokecherry answered 17/4, 2019 at 7:16 Comment(0)
O
0

So I figured it out! I don't know why, but it turns out that my main project's root folder (main 'app' module) was on the file type ignore list. All you have to do is remove the folder name from the list (highlighted in picture below).

Oddly enough, this also resolved some the other anomalies I was experiencing. One issue was I could never see the AndroidManifest file in 'manifests' folder of the Hierarchy/Project Viewer ('Android' selected). Another issue was whenever I'd build and run the app, I'd get a warning about the AndroidManifest and have to click "Continue Anyway". Also, the app wouldn't auto-launch once installed.

Ignore List

Ozzy answered 10/4, 2015 at 16:44 Comment(0)
E
0

My problem was that I, after recently changing the package name, accidentally added a blank space in the Manifest package name.

Everyway answered 14/8, 2015 at 10:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.