1 page.title=Android Studio Tips and Tricks 2 3 @jd:body 4 5 <div id="qv-wrapper"> 6 <div id="qv"> 7 <h2>See also</h2> 8 <ul> 9 <li><a href="http://confluence.jetbrains.com/display/IntelliJIDEA/Working+in+Eclipse+Compatibility+Mode" class="external-link" 10 >Eclipse Compatibility Mode</a></li> 11 <li><a href="http://confluence.jetbrains.com/display/IntelliJIDEA/FAQ+on+Migrating+to+IntelliJ+IDEA" class="external-link" 12 >FAQ on Migrating</a></li> 13 <li><a href="http://android-developers.blogspot.com/2013/06/adding-backend-to-your-app-in-android.html" 14 class="external-link">Adding a Backend to Your App In Android Studio</a></li> 15 </ul> 16 </div> 17 </div> 18 19 <p>If you're unfamiliar with the IntelliJ IDEA interface, you might be wondering 20 how to accomplish some common tasks in Android Studio. This page provides some tips 21 to help you get going.</p> 22 23 <p>For complete user documentation for the IntelliJ IDEA interface 24 (upon which Android Studio is based), refer to the 25 <a href="http://www.jetbrains.com/idea/index.html">IntelliJ IDEA documentation</a>.</p> 26 27 <div class="figure" style="width:200px"> 28 <img src="{@docRoot}images/tools/project-layout.png" alt="" /> 29 <p class="img-caption"><strong>Figure 1.</strong> Gradle project structure</p> 30 </div> 31 32 <h2 id="Project">Project Structure</h2> 33 34 <p>When you create a new project in Android Studio (or 35 <a href="{@docRoot}sdk/installing/migrate.html">migrate a project from Eclipse</a>), 36 you'll notice that the project structure appears differently than you may be used to. 37 As shown in figure 1, almost all your project files are now inside the {@code src/} directory, 38 including resources and the manifest file.</p> 39 40 <p>The new project structure is due to the switch to a Gradle-based build system. This structure 41 provides more flexibility to the build process and will allow multiple build variants (a feature not 42 yet fully implemented). Everything still behaves as you expect, but some of the files have moved 43 around. For the most part, you should need to modify only the files under the {@code src/} 44 directory. More information about the Gradle project structure is available in the 45 <a href="http://tools.android.com/tech-docs/new-build-system/user-guide">Gradle 46 Plugin User Guide</a>.</p> 47 48 49 50 <h2 id="Basics">Basic Operations</h2> 51 52 <p>The following topics describe how to perform 53 some basic development tasks with Android Studio.</p> 54 55 <p class="note"><strong>Note:</strong> This section lists Android Studio keyboard shortcuts 56 for the default keymap. To change the default keymap on Windows and Linux, go to 57 <strong>File</strong> > <strong>Settings</strong> > <strong>Keymap</strong>. To change 58 the default keymap on Mac OS X, go to <strong>Android Studio</strong> > 59 <strong>Preferences</strong> > <strong>Keymap</strong>.</p> 60 61 <h3>Creating virtual devices</h3> 62 63 <p>All the capabilities of the <a href="{@docRoot}tools/devices/managing-avds.html">Android 64 Virtual Device Manager</a> are accessible directly from 65 the Android Studio interface. Click the <strong>Android Virtual Device Manager</strong> 66 <img src="{@docRoot}images/tools/avd-manager-studio.png" 67 style="vertical-align:bottom;margin:0;height:19px" /> in the toolbar to open it and create 68 new virtual devices for running your app in the emulator.</p> 69 70 71 <h3>Installing SDK updates</h3> 72 73 <p>The <a href="{@docRoot}tools/help/sdk-manager.html">SDK Manager</a> 74 is also accessible to download new Android tools, platforms, and libraries 75 for your app. Click the <strong>SDK Manager</strong> 76 <img src="{@docRoot}images/tools/sdk-manager-studio.png" 77 style="vertical-align:bottom;margin:0;height:19px" /> in the toolbar to open it and check 78 for updates.</p> 79 80 81 <h3>Creating new files</h3> 82 83 <p>You can quickly add new code and resource files by clicking the appropriate directory in the 84 <strong>Project</strong> pane and pressing ALT + INSERT on Windows and Linux or COMMAND + N on Mac. 85 Based on the type of directory selected, Android Studio offers to create the appropriate file 86 type.</p> 87 88 <p>For example, if you select a layout directory, press ALT + INSERT on Windows, and select 89 <strong>Layout resource file</strong>, a dialog opens so you can name the file (you can exclude 90 the {@code .xml} suffix) and choose a root view element. The editor then switches to the layout 91 design editor so you can begin designing your layout.</p> 92 93 94 <h3>Creating layouts</h3> 95 96 <p>Android Studio offers an advanced layout editor that allows you to drag-and-drop widgets 97 into your layout and preview your layout while editing the XML.</p> 98 99 <p>While editing in the <strong>Text</strong> view, you can preview the layout on devices by opening 100 the <strong>Preview</strong> pane available on the right side of the window. Within the 101 Preview pane, you can modify the preview by changing various options at the top of the pane, including 102 the preview device, layout theme, platform version and more. To preview the layout on multiple 103 devices simultaneously, select <strong>Preview All Screen Sizes</strong> from the device drop-down. 104 </p> 105 106 <p>You can switch to the graphical editor by clicking <strong>Design</strong> at the 107 bottom of the window. While editing in the Design view, you can show and hide the 108 widgets available to drag-and-drop by clicking <strong>Palette</strong> on the 109 left side of the window. Clicking <strong>Designer</strong> on the right side of the window reveals 110 a panel with a layout hierarchy and a list of properties for each view in the layout.</p> 111 112 113 <h3>Debugging</h3> 114 115 <p>When you build and run your app with Android Studio, you can view adb and device log messages 116 (logcat) in the DDMS pane by clicking <strong>Android</strong> at the bottom of the window.</p> 117 118 <p>If you want to debug your app with the <a 119 href="{@docRoot}tools/help/monitor.html">Android Debug Monitor</a>, you can launch it by 120 clicking <strong>Monitor</strong> <img src="{@docRoot}images/tools/monitor-studio.png" 121 style="vertical-align:bottom;margin:0;height:19px" /> in the toolbar. The Debug Monitor is where 122 you can find the complete set of <a href="{@docRoot}tools/debugging/ddms.html">DDMS</a> 123 tools for profiling your app, controlling device 124 behaviors, and more. It also includes the Hierarchy Viewer tools to help 125 <a href="{@docRoot}tools/debugging/debugging-ui.html">optimize your layouts</a>.</p> 126 127 128 129 130 131 <h2 id="KeyCommands">Keyboard Commands</h2> 132 133 <p>The following tables list keyboard shortcuts for common operations.</p> 134 135 <p class="note"><strong>Note:</strong> If you're using Mac OS X, update your keymap to use 136 the Mac OS X 10.5+ version keymaps under <strong>Android Studio > Preferences > Keymap</strong>.</p> 137 138 139 140 <p class="table-caption"><strong>Table 1.</strong> Programming key commands</p> 141 <table> 142 <tr><th>Action</th><th>Android Studio Key Command</th></tr> 143 144 <tr> 145 <td>Command look-up (autocomplete command name)</td> 146 <td>CTRL + SHIFT + A</td> 147 </tr> 148 149 <tr> 150 <td>Project quick fix</td> 151 <td>ALT + ENTER</td> 152 </tr> 153 154 <tr> 155 <td>Reformat code</td> 156 <td>CTRL + ALT + L (Win)<br> 157 OPTION + CMD + L (Mac)</td> 158 </tr> 159 160 <tr> 161 <td>Show docs for selected API</td> 162 <td>CTRL + Q (Win)<br> 163 F1 (Mac)</td> 164 </tr> 165 166 <tr> 167 <td>Show parameters for selected method</td> 168 <td>CTRL + P</td> 169 </tr> 170 171 <tr> 172 <td>Generate method</td> 173 <td>ALT + Insert (Win)<br> 174 CMD + N (Mac)</td> 175 </tr> 176 177 <tr> 178 <td>Jump to source</td> 179 <td>F4 (Win)<br> 180 CMD + down-arrow (Mac)</td> 181 </tr> 182 183 <tr> 184 <td>Delete line</td> 185 <td>CTRL + Y (Win)<br> 186 CMD + Backspace (Mac)</td> 187 </tr> 188 189 <tr> 190 <td>Search by symbol name</td> 191 <td>CTRL + ALT + SHIFT + N (Win)<br> 192 OPTION + CMD + O (Mac)</td> 193 </tr> 194 195 </table> 196 197 198 199 200 <p class="table-caption"><strong>Table 2.</strong> Project and editor key commands</p> 201 <table> 202 <tr><th>Action</th><th>Android Studio Key Command</th></tr> 203 204 <tr> 205 <td>Build</td> 206 <td>CTRL + F9 (Win)<br> 207 CMD + F9 (Mac)</td> 208 </tr> 209 210 <tr> 211 <td>Build and run</td> 212 <td>SHIFT + F10 (Win)<br> 213 CTRL + R (Mac)</td> 214 </tr> 215 216 <tr> 217 <td>Toggle project visibility</td> 218 <td>ALT + 1 (Win)<br> 219 CMD + 1 (Mac)</td> 220 </tr> 221 222 <tr> 223 <td>Navigate open tabs</td> 224 <td>ALT + left-arrow; ALT + right-arrow (Win)<br> 225 CTRL + left-arrow; CTRL + right-arrow (Mac)</td> 226 </tr> 227 228 </table> 229 230 <p>For a complete keymap reference guide, see the <a 231 href="http://www.jetbrains.com/idea/documentation/index.jsp">IntelliJ IDEA</a> 232 documentation.</p> 233 234