2

Please note that this question is not the same as the ones relating to filenames.

In styling a larger app, many style names and color names are necessary, and capital letters are allowed for both by Android Studio and the compiler. See e.g. CustomText here.

However, if I use the built-in Refactor > Rename dialog, I can no longer do this for color names. This was possible in BumbleBee.

Is there a solution short of downgrading to BumbleBee? It would be an improvement to readability. Please see the screenshot, where I'm not allowed to refactor an existing color name to the same name, which has a capital letter.

Screenshot of dialog in Android Studio Dolphin

I've searched under File > Settings for "refactor", but only found two options, neither of which change the behavior.

Henrik Erlandsson
  • 3,797
  • 5
  • 43
  • 63
  • 1
    This appears to [be fixed for some future version of the IDE](https://issuetracker.google.com/issues/259111489). Since that was only a week ago, it probably has not made it into Electric Eel or Flamingo pre-release builds just yet. "Is there a solution short of downgrading to BumbleBee?" -- change the resource manually, without using the refactoring dialog. For example, you could use the refactoring dialog to rename the color to something nice and unique (yet with a lowercase character), then use a text editor or other tools to replace the unique name with your desired capitalized color name. – CommonsWare Nov 21 '22 at 16:30
  • You'd like to avoid replace, that's what Refactor is for, but I should have thought of the in-between unique term... I've used that trick before with plain replace for CSV files. This will work flawlessly and without risk of error, thanks! Post it as answer and I will accept. – Henrik Erlandsson Nov 22 '22 at 10:18

1 Answers1

0

The good news, relatively speaking, is that this should be fixed in the future. This doesn't feel like something that will make it into a Dolphin patch release, but that's just a guess.

Since all the relevant files are text files, some sort of text-based global search-and-replace would work. However, at least in your screenshot, the affected color resource name might be something like blue, which is kinda generic.

So, I'd go with a middle-ground approach:

  1. Use the refactor dialog to rename blue to something else that matches the (buggy) naming rule but is otherwise nice and unique. For example, you could rename it to blueThatIWantToRenameToSomethingElseKThxBye.

  2. Use a global search-and-replace of the source files to replace blueThatIWantToRenameToSomethingElseKThxBye to your desired resource name (in this case, Blue).

This approach avoids accidentally renaming blue in, say, a source comment, to Blue.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491