Android Studio is not just a development environment, but a powerful tool with dozens of hidden functions that save hours of work. One of the key skills of an effective programmer is the ability to quickly find the necessary code, resources, or errors in a project. But the standard search by Ctrl+F covers only 5% of the possibilities. In this article, we will look at professional search techniques: from basic hotkeys to advanced filters with regular expressions and search by code structure.
You will learn how to search not only by text, but also by file types, annotations, commits in Git and even by UI elements in XML. And also - how to set Android Studio so that it itself suggests where you have already looked and what you have found before. This guide will be useful for both a beginner who gets lost in hundreds of project files, and an experienced developer who needs to optimize his routine.
1. Basic search: hot keys and quick filters
Let's start with the basics, which not everyone knows. In Android Studio there are two main types of search:
- ๐ Local search - within one file (
Ctrl+Fon Windows/Linux,Cmd+Fon Mac). Works like in a text editor, but with support for regular expressions. - ๐ Global search โthroughout the entire project (
Ctrl+Shift+F/Cmd+Shift+F). Searches in code, resources, libraries and even in generators (build files).
To narrow down the global search results, use the filters in the left panel of the search window:
- ๐ Directory โ search only in a specific folder (for example,
res/layoutorsrc/main/java). - ๐ฅ๏ธ Scope โlimit the search area (only Project Files, Tests, Open Files etc.).
- ๐ค File Mask โsearch only in files with a specific extension (for example,
.ktfor Kotlin or.xmlfor markup).
Example: you need to find all mentions of the string "user_not_found", but only in localization files. Enter the query, then in the File Mask field specify *.xml, and in Directory select res/values. The system will instantly show all occurrences in strings.xml and other language files.
2. Search by code structure: when a text query does not work
Suppose you need to find all the places where a method is called viewModel.loadData(), but only with a specific argument. will return hundreds of false positives. Structural Search (Edit โ Find โ Search Structurally or Ctrl+Shift+S).
This tool does not look for text, but code templates. For example, you can find:
- ๐ All cycles
for, where the variable is calledi. - ๐ฆ All calls
LiveData.observe()with a lambda expression. - โ ๏ธ All places where
nullis passed to a method without checking.
How it works:
- Open
Search Structurally. - In the field Search template enter the template (for example,
$method$($param$)). - Specify restrictions: for example,
$method$.text() == "loadData". - Click
Find.
The system will show all the places where a method loadData is called with one argument, regardless of the variable name. This is especially useful for refactoring or finding potential bugs.
Save frequently used Structural Search templates in Edit โ Find โ Save Search Template. They will be available in the drop-down list the next time you search.
3. Search by annotations and metadata
In large projects, annotations (for example, @Deprecated, @VisibleForTesting or custom ones) annotations like @BindView from ButterKnife help you quickly find outdated code, test methods, or View bindings. To search by annotations:
- Open global search (
Ctrl+Shift+F). - In the query field, enter
@AnnotationName(for example,@Deprecated). - In the filter File Mask specify
.javaor.kt.
For more complex queries, use regular expressions. For example, to find all methods with an annotation @Test from JUnit:
@Test\s+\w+\s*\([^)]*\)
This expression looks for:
- ๐ Word
@Test. - ๐ Followed by one or more whitespace characters (
\s+). - ๐ Then the method name (
\w+). - ๐ And parentheses with parameters (
\([^)]*\)).
The result is a list of all test methods in the project, even if they are scattered across different classes.
How to search through several annotations at the same time?
Use the operator | (OR) in a regular expression. For example, @(Deprecated|VisibleForTesting) will find code with any of these annotations.
4. Search in XML: markup, styles and resources
Developers are often faced with the need to find:
- ๐จ All occurrences of a particular style (for example,
@style/AppTheme.NoActionBar). - ๐ฑ All
Viewwith a specific ID (for example,@+id/btn_submit). - ๐ All links to a specific drawable (for example,
@drawable/ic_arrow_back).
To do this:
- Open the global search (
Ctrl+Shift+F). - In the field File Mask specify
*.xml. - Enter the query, for example,
android:id="@+id/btn_submit". - Tick the checkbox Regexif you want to use a regular expression.
Example: to find all buttons with the text "Submit" (regardless of case), use:
<Button.android:text="[sS]ubmit".>
This expression searches for tags <Button>that have an attribute android:text with a value Submit or submit.
โ ๏ธ Attention: When searching in XML, keep in mind that attributes can be written in different orders. Use .* to skip any characters between attributes.
5. Search in the history of changes and Git
If you need to find who and when a specific piece of code, or roll back changes, use the built-in tools Android Studio to work with Git:
| Task | Hot keys | Where to look |
|---|---|---|
| View file change history | Alt+Shift+C (Windows/Linux)Option+Shift+C (Mac) |
Tab Git โ Show History |
| Find all commits that mention text | Ctrl+Shift+A โ "Search Git History" |
Panel Version Control โ Log |
| Compare file versions | Ctrl+D (on the selected commit) |
Context menu in Git history |
| Find the author of a line of code | Move the cursor over the line โ Git โ Annotate |
Right mouse button on the code |
Example: you found a bug that appeared after the last release. To find out who made the problematic changes:
- Open the file with the bug.
- Click
Alt+Shift+C(orOption+Shift+Con Mac). - Look through the list of commits and find the one that after which the bug appeared.
- Right-click on the commit and select
Show Diffto see the changes.
โ ๏ธ Attention: If the project uses not Git, but another version control system (for example, Mercurial or SVN), paths to functions may differ. Check the settings in VCS โ Enable Version Control Integration.
6. Advanced techniques: character searches, regular expressions and plugins
For experienced developers Android Studio offers tools that go beyond standard search:
- ๐ค Search by characters (Unicode): find all non-ASCII characters in code (for example, Cyrillic or Emoji) using a regular expression
[\u0400-\u04FF](for the Russian alphabet). - ๐ Search by structure JSON/XML: plugin JSON Parser allows you to search by keys in JSON files, even if they are nested.
- ๐ ๏ธ Database search: if the project uses Room, the plugin Android Room Schema Visualizer will show all entities and their relationships.
An example of a regular expression for searching email addresses in code:
[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
This expression will find all lines of the form user@example.com, even if they are written as parts of larger text (for example, in logs or comments).
For working with regular expressions in Android Studio the following constructs are supported:
- ๐
\dโ any number. - ๐
\wโ any alphanumeric character. - ๐
.*โ any sequence of characters. - ๐
[abc]โany character from the seta,borc.
Make sure that the project is indexed (there is no red indicator at the bottom of the screen)
Close unnecessary files to speed up the search
Save all changes before global search
Use Scope to narrow the search area-->
7. Setting up and optimizing search
Android Studio allows you to customize search behavior to suit your needs. To open Settings, go to File โ Settings โ Editor โ General โ Search (or Android Studio โ Preferences โ Editor โ General โ Search on Mac). Here you can:
- โก Enable incremental search (shows results as you type).
- ๐ Customize cyclic search (after the last result returns to first).
- ๐ Add custom search areas (for example, exclude folder
build). - ๐ค Edit case sensitivity by default.
One of the most useful parameters is "Highlight usages on caret move" (in Settings โ Editor โ General โ Code Folding). When this option is enabled, Android Studio will highlight all occurrences of the variable or method when hovering the cursor over it. This speeds up navigation through the code without explicit search.
It is also recommended to configure hotkeys for frequently used actions. For example, assign a separate combination for:
- ๐
Search Everywhere(Double Shiftdefault). data-i="220">To change hotkeys, go to - ๐
Replace in Path(Ctrl+Shift+R). - ๐
Recent Files(Ctrl+E).
To change hotkeys, go to File โ Settings โ Keymap.
Regularly clear the search cache (File โ Invalidate Cachesif Android Studio starts to slow down during global search. This is especially true for large projects with thousands of files.
FAQ: Answers to frequently asked questions
How to find all TODO notes in a project?
The Android Studio has built-in support for TODOcomments. Click Alt+6 (or Cmd+6 on Mac) to open the TODOpanel. It will show all comments with tags TODO, FIXME, NOTE and others. You can also use global search with the query // TODO or / TODO /.
Why does the search not find files in the folder build?
By default Android Studio excludes folders build, .git and .idea from search because they contain generated files. To enable them, uncheck "Skip generated sources" in the global search window or add the folder to Scope manually.
Is it possible to search by comments in the code?
Yes, comments are indexed in the same way as the main code. To find a comment, use the global search (Ctrl+Shift+F) and enter the text of the comment. For example, the query // Fix for issue #123 will find all one-line comments with this phrase. For multi-line comments, use / ... /.
How to save search results for future use?
Search results can be exported to a file. To do this:
- Perform a search.
- In the results window, click on the gear icon (โ๏ธ) โ
Export Results. - Select a format (
TXTorHTML) and save file.
This is useful for documenting changes or sharing with colleagues.
Why is search slow in large projects?
Search speed depends on:
- ๐ฅ๏ธ Computer power (disk speed is especially important).
- ๐ Project size and number of files.
- ๐ Indexing settings (
File โ Settings โ Build, Execution, Deployment โ Compiler โ Excludes).
To speed up the search:
- Exclude unnecessary folders from indexing.
- Close unused files.
- Use Scope to narrow the search area.