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 <h3>Creating virtual devices</h3> 56 57 <p>All the capabilities of the <a href="{@docRoot}tools/devices/managing-avds.html">Android 58 Virtual Device Manager</a> are accessible directly from 59 the Android Studio interface. Click the <strong>Android Virtual Device Manager</strong> 60 <img src="{@docRoot}images/tools/avd-manager-studio.png" 61 style="vertical-align:bottom;margin:0;height:19px" /> in the toolbar to open it and create 62 new virtual devices for running your app in the emulator.</p> 63 64 65 <h3>Installing SDK updates</h3> 66 67 <p>The <a href="{@docRoot}tools/help/sdk-manager.html">SDK Manager</a> 68 is also accessible to download new Android tools, platforms, and libraries 69 for your app. Click the <strong>SDK Manager</strong> 70 <img src="{@docRoot}images/tools/sdk-manager-studio.png" 71 style="vertical-align:bottom;margin:0;height:19px" /> in the toolbar to open it and check 72 for updates.</p> 73 74 75 <h3>Creating new files</h3> 76 77 <p>You can quickly add new code and resource files by clicking the appropriate directory in the 78 <strong>Project</strong> pane and pressing CTRL + N (CMD + N, on Mac). Based on the type of 79 directory selected, Android Studio offers to create the appropriate file type.</p> 80 81 <p>For example, if you select a layout directory, press CTRL + N, and select 82 <strong>Layout resource file</strong>, a dialog opens so you can name the file (you can exclude 83 the {@code .xml} suffix) and choose a root view element. The editor then switches to the layout 84 design editor so you can begin designing your layout.</p> 85 86 87 <h3>Creating layouts</h3> 88 89 <p>Android Studio offers an advanced layout editor that allows you to drag-and-drop widgets 90 into your layout and preview your layout while editing the XML.</p> 91 92 <p>While editing in the <strong>Text</strong> view, you can preview the layout on devices by opening 93 the <strong>Preview</strong> pane available on the right side of the window. Within the 94 Preview pane, you can modify the preview by changing various options at the top of the pane, including 95 the preview device, layout theme, platform version and more. To preview the layout on multiple 96 devices simultaneously, select <strong>Preview All Screen Sizes</strong> from the device drop-down. 97 </p> 98 99 <p>You can switch to the graphical editor by clicking <strong>Design</strong> at the 100 bottom of the window. While editing in the Design view, you can show and hide the 101 widgets available to drag-and-drop by clicking <strong>Palette</strong> on the 102 left side of the window. Clicking <strong>Designer</strong> on the right side of the window reveals 103 a panel with a layout hierarchy and a list of properties for each view in the layout.</p> 104 105 106 <h3>Debugging</h3> 107 108 <p>When you build and run your app with Android Studio, you can view adb and device log messages 109 (logcat) in the DDMS pane by clicking <strong>Android</strong> at the bottom of the window.</p> 110 111 <p>If you want to debug your app with the <a 112 href="{@docRoot}tools/help/monitor.html">Android Debug Monitor</a>, you can launch it by 113 clicking <strong>Monitor</strong> <img src="{@docRoot}images/tools/monitor-studio.png" 114 style="vertical-align:bottom;margin:0;height:19px" /> in the toolbar. The Debug Monitor is where 115 you can find the complete set of <a href="{@docRoot}tools/debugging/ddms.html">DDMS</a> 116 tools for profiling your app, controlling device 117 behaviors, and more. It also includes the Hierarchy Viewer tools to help 118 <a href="{@docRoot}tools/debugging/debugging-ui.html">optimize your layouts</a>.</p> 119 120 121 122 123 124 <h2 id="KeyCommands">Keyboard Commands</h2> 125 126 <p>The following tables list keyboard shortcuts for common operations.</p> 127 128 <p class="note"><strong>Note:</strong> If you're using Mac OS X, update your keymap to use 129 the Mac OS X 10.5+ version keymaps under <strong>Android Studio > Preferences > Keymap</strong>.</p> 130 131 132 133 <p class="table-caption"><strong>Table 1.</strong> Programming key commands</p> 134 <table> 135 <tr><th>Action</th><th>Android Studio Key Command</th></tr> 136 137 <tr> 138 <td>Command look-up (autocomplete command name)</td> 139 <td>CTRL + SHIFT + A</td> 140 </tr> 141 142 <tr> 143 <td>Project quick fix</td> 144 <td>ALT + ENTER</td> 145 </tr> 146 147 <tr> 148 <td>Reformat code</td> 149 <td>CTRL + ALT + L (Win)<br> 150 OPTION + CMD + L (Mac)</td> 151 </tr> 152 153 <tr> 154 <td>Show docs for selected API</td> 155 <td>CTRL + Q (Win)<br> 156 F1 (Mac)</td> 157 </tr> 158 159 <tr> 160 <td>Show parameters for selected method</td> 161 <td>CTRL + P</td> 162 </tr> 163 164 <tr> 165 <td>Generate method</td> 166 <td>ALT + Insert (Win)<br> 167 CMD + N (Mac)</td> 168 </tr> 169 170 <tr> 171 <td>Jump to source</td> 172 <td>F4 (Win)<br> 173 CMD + down-arrow (Mac)</td> 174 </tr> 175 176 <tr> 177 <td>Delete line</td> 178 <td>CTRL + Y (Win)<br> 179 CMD + Backspace (Mac)</td> 180 </tr> 181 182 <tr> 183 <td>Search by symbol name</td> 184 <td>CTRL + ALT + SHIFT + N (Win)<br> 185 OPTION + CMD + O (Mac)</td> 186 </tr> 187 188 </table> 189 190 191 192 193 <p class="table-caption"><strong>Table 2.</strong> Project and editor key commands</p> 194 <table> 195 <tr><th>Action</th><th>Android Studio Key Command</th></tr> 196 197 <tr> 198 <td>Build</td> 199 <td>CTRL + F9 (Win)<br> 200 CMD + F9 (Mac)</td> 201 </tr> 202 203 <tr> 204 <td>Build and run</td> 205 <td>SHIFT + F10 (Win)<br> 206 CTRL + R (Mac)</td> 207 </tr> 208 209 <tr> 210 <td>Toggle project visibility</td> 211 <td>ALT + 1 (Win)<br> 212 CMD + 1 (Mac)</td> 213 </tr> 214 215 <tr> 216 <td>Navigate open tabs</td> 217 <td>ALT + left-arrow; ALT + right-arrow (Win)<br> 218 CTRL + left-arrow; CTRL + right-arrow (Mac)</td> 219 </tr> 220 221 </table> 222 223 <p>For a complete keymap reference guide, see the <a 224 href="http://www.jetbrains.com/idea/documentation/index.jsp">IntelliJ IDEA</a> 225 documentation.</p> 226 227