Home | History | Annotate | Download | only in installing
      1 page.title=Android Studio Tips and Tricks
      2 @jd:body
      3 
      4 <div id="qv-wrapper">
      5 <div id="qv">
      6 
      7     <h2>In this document</h2>
      8     <ol>
      9       <li><a href="#productivity-features">Productivity Features</a></li>
     10       <li><a href="#intellij">Working with IntelliJ</a></li>
     11       <li><a href="#key-commands">Key Commands</a></li>
     12     </ol>
     13 
     14   <h2>See also</h2>
     15   <ol>
     16     <li><a href="{@docRoot}sdk/index.html">Download Android Studio</a></li>
     17     <li><a href="http://wiki.jetbrains.net/intellij/Android">IntelliJ IDEA Android Tutorials</a></li>
     18     <li><a href="http://confluence.jetbrains.com/display/IntelliJIDEA/FAQ+on+Migrating+to+IntelliJ+IDEA">IntelliJ FAQ on migrating to IntelliJ IDEA</a></li>
     19   </ol>
     20 
     21 </div>
     22 </div>
     23 
     24 <p>If you're unfamiliar with using Android Studio and the IntelliJ IDEA interface, this page
     25 provides some tips to help you get started with some of the most common tasks and productivity
     26 enhancements. </p>
     27 
     28 
     29 <h2 id="productivity-features">Productivity Features</h2>
     30 
     31 <p>Android Studio includes a number of features to help you be more productive in your coding.
     32 This section notes a few of the key features to help you work quickly and efficiently.
     33 </p>
     34 
     35 
     36 <h3>Smart Rendering</h3>
     37 <p>With smart rendering, Android Studio displays links for quick fixes to rendering errors.
     38 For example, if you add a button to the layout without specifying the <em>width</em> and
     39 <em>height</em> atttributes, Android Studio displays the rendering message <em>Automatically
     40 add all missing attributs</em>. Clicking the message adds the missing attributes to the layout.</p>
     41 
     42 
     43 <h3> Bitmap rendering in the debugger</h3>
     44 <p>While debugging, you can now right-click on bitmap variables in your app and invoke
     45 <em>View Bitmap</em>. This fetches the associated data from the debugged process and renders
     46 the bitmap in the debugger. </p>
     47 <p><img src="{@docRoot}images/tools/studio-bitmap-rendering.png" style="width:350px"/></p>
     48 <p class="img-caption"><strong>Figure 1.</strong> Bitmap Rendering</p>
     49 
     50 
     51 <h3>Output window message filtering</h3>
     52 <p>When checking build results, you can filter messages by <em>message type</em> to quickly
     53 locate messages of interest.</p>
     54 <img src="{@docRoot}images/tools/studio-outputwindowmsgfiltering.png" style="width:200px"style="width:200px" />
     55 <p class="img-caption"><strong>Figure 2.</strong> Filter Build Messages</p>
     56 
     57 
     58 <h3>Hierarchical parent setting</h3>
     59 <p>The activity parent can now be set in the Activity Wizard when creating a new
     60 activity. Setting a <em>hierarchal parent</em> sets the {@code Up} button to automatically
     61 appear in the app's Action bar when viewing a child activity, so the {@code Up}
     62 button no longer needs to be manually specified in the <em>menu.xml</em> file.</p>
     63 
     64 
     65 <h3>Creating layouts</h3>
     66 <p>Android Studio offers an advanced layout editor that allows you to drag-and-drop widgets
     67 into your layout and preview your layout while editing the XML.</p>
     68 
     69 <p>While editing in the <strong>Text</strong> view, you can preview the layout on devices by
     70 opening the <strong>Preview</strong> pane available on the right side of the window. Within the
     71 Preview pane, you can modify the preview by changing various options at the top of the pane,
     72 including the preview device, layout theme, platform version and more. To preview the layout on
     73 multiple devices simultaneously, select <strong>Preview All Screen Sizes</strong> from the
     74 device drop-down.</p>
     75 <p><img src="{@docRoot}images/tools/studio-previewall.png" style="width:350px"/></p>
     76 <p class="img-caption"><strong>Figure 3.</strong> Preview All Screens</p>
     77 
     78 <p>You can switch to the graphical editor by clicking <strong>Design</strong> at the
     79 bottom of the window. While editing in the Design view, you can show and hide the
     80 widgets available to drag-and-drop by clicking <strong>Palette</strong> on the left side of the
     81 window. Clicking <strong>Designer</strong> on the right side of the window reveals a panel
     82 with a layout hierarchy and a list of properties for each view in the layout.</p>
     83 
     84 
     85 <h2 id="intellij">Working with IntelliJ</h3>
     86 
     87 <p>This section list just a few of the code editing
     88 practices you should consider using when creating Android Studio apps. </p>
     89 
     90 <p>For complete user documentation for the IntelliJ IDEA interface (upon which Android Studio
     91 is based), refer to the
     92 <a href="http://www.jetbrains.com/idea/documentation/index.jsp">IntelliJ IDEA documentation</a>.</p>
     93 
     94 
     95 <h3><em>Alt + Enter</em> key binding</h3>
     96 <p>For quick fixes to coding errors, the IntelliJ powered IDE implements the <em>Alt + Enter</em>
     97 key binding to fix errors (missing imports, variable assignments, missing references, etc) when
     98 possible, and if not, suggest the most probable solution. </p>
     99 
    100 
    101 <h3><em>Ctrl + D</em> key binding</h3>
    102 <p>The <em>Ctrl + D</em> key binding is great for quickly duplicating code lines or fragments.
    103 Simply select the desired line or fragment and enter this key binding. </p>
    104 
    105 
    106 <h3>Navigate menu</h3>
    107 <p>In case you're not familiar with an API class, file or symbol, the <em>Navigate</em> menu lets
    108 you jump directly to the class of a method or field name without having to search through
    109 individual classes. </p>
    110 
    111 
    112 <h3>Inspection scopes</h3>
    113 <p>Scopes set the color of code segments for easy code identification and location. For example,
    114 you can set a scope to identify all code related to a specific action bar.   </p>
    115 
    116 
    117 <h3>External annotations</h3>
    118 <p>Specify annotations within the code or from an external annotation file. The Android Studio
    119 IDE keeps track of the restrictions and validates compliance, for example setting the data type
    120 of a string as not null.</p>
    121 
    122 
    123 <h3>Injecting languages</h3>
    124 <p>With language injection, the Android Studio IDE allows you to work with islands of different
    125 languages embedded in the source code. This extends the syntax, error highlighting and coding
    126 assistance to the embedded language. This can be especially useful for checking regular expression
    127 values inline, and validating XML and SQL statments.</p>
    128 
    129 
    130 <h3>Code folding</h3>
    131 <p>This allows you to selectively hide and display sections of the code for readability. For
    132 example, resource expressions or code for a nested class can be folded or hidden in to one line
    133 to make the outer class structure easier to read. The inner clas can be later expanded for
    134 updates. </p>
    135 
    136 
    137 <h3>Image and color preview</h3>
    138 <p>When referencing images and icons in your code, a preview of the image or icon appears
    139 (in actual size at different densities) in the code margin to help you verify the image or icon
    140 reference.  Pressing {@code F1} with the preview image or icon selected displays resource asset
    141 details, such as the <em>dp</em> settings.   </p>
    142 
    143 <h3>Quick F1 documentation</h3>
    144 <p>You can now inspect theme attributes using <strong>View > Quick Documentation</strong>
    145 (<strong>F1</strong>),
    146 see the theme inheritance hierarchy, and resolve values for the various attributes.</p>
    147 
    148 <p>If you invoke <strong> View > Quick Documentation</strong> (usually bound to F1) on the theme
    149 attribute <em>?android:textAppearanceLarge</em>, you will see the theme inheritance hierarchy and
    150 resolved values for the various attributes that are pulled in.</p>
    151 
    152 
    153 <h3>New Allocation Tracker integration in the Android/DDMS window</h3>
    154 <p>You can now inspect theme attributes using <strong> View > Quick Documentation
    155 </strong> <code>F1</code>, see the theme inheritance hierarchy, and resolved values for the
    156 various attributes.</p>
    157 <img src="{@docRoot}images/tools/studio-allocationtracker.png" style="width:300px" />
    158 <p class="img-caption"><strong>Figure 4.</strong> Allocation Tracker</p>
    159 
    160 
    161 <h3 id="key-commands">Keyboard Commands</h3>
    162 
    163 <p>The following tables list keyboard shortcuts for common operations.</p>
    164 
    165 <p class="note"><strong>Note:</strong> This section lists Android Studio keyboard shortcuts
    166 for the default keymap. To change the default keymap on Windows and Linux, go to
    167 <strong>File</strong> &gt; <strong>Settings</strong> &gt; <strong>Keymap</strong>. If you're
    168 using Mac OS X, update your keymap to use the Mac OS X 10.5+ version keymaps under
    169 <strong>Android Studio > Preferences > Keymap</strong>.</p>
    170 
    171 
    172 <p class="table-caption"><strong>Table 1.</strong> Programming key commands</p>
    173 <table>
    174 <tr><th>Action</th><th>Android Studio Key Command</th></tr>
    175 
    176 <tr>
    177   <td>Command look-up (autocomplete command name)</td>
    178   <td>CTRL + SHIFT + A</td>
    179 </tr>
    180 
    181 <tr>
    182   <td>Project quick fix</td>
    183   <td>ALT + ENTER</td>
    184 </tr>
    185 
    186 <tr>
    187   <td>Reformat code</td>
    188   <td>CTRL + ALT + L (Win)<br>
    189       OPTION + CMD + L (Mac)</td>
    190 </tr>
    191 
    192 <tr>
    193   <td>Show docs for selected API</td>
    194   <td>CTRL + Q (Win)<br>
    195       F1 (Mac)</td>
    196 </tr>
    197 
    198 <tr>
    199   <td>Show parameters for selected method</td>
    200   <td>CTRL + P</td>
    201 </tr>
    202 
    203 <tr>
    204   <td>Generate method</td>
    205   <td>ALT + Insert (Win)<br>
    206       CMD + N (Mac)</td>
    207 </tr>
    208 
    209 <tr>
    210   <td>Jump to source</td>
    211   <td>F4 (Win)<br>
    212       CMD + down-arrow (Mac)</td>
    213 </tr>
    214 
    215 <tr>
    216   <td>Delete line</td>
    217   <td>CTRL + Y (Win)<br>
    218       CMD + Backspace (Mac)</td>
    219 </tr>
    220 
    221 <tr>
    222   <td>Search by symbol name</td>
    223   <td>CTRL + ALT + SHIFT + N (Win)<br>
    224       OPTION + CMD + O (Mac)</td>
    225 </tr>
    226 
    227 </table>
    228 
    229 
    230 
    231 
    232 <p class="table-caption"><strong>Table 2.</strong> Project and editor key commands</p>
    233 <table>
    234 <tr><th>Action</th><th>Android Studio Key Command</th></tr>
    235 
    236 <tr>
    237   <td>Build</td>
    238   <td>CTRL + F9 (Win)<br>
    239       CMD + F9 (Mac)</td>
    240 </tr>
    241 
    242 <tr>
    243   <td>Build and run</td>
    244   <td>SHIFT + F10 (Win)<br>
    245       CTRL + R (Mac)</td>
    246 </tr>
    247 
    248 <tr>
    249   <td>Toggle project visibility</td>
    250   <td>ALT + 1 (Win)<br>
    251       CMD + 1 (Mac)</td>
    252 </tr>
    253 
    254 <tr>
    255   <td>Navigate open tabs</td>
    256   <td>ALT + left-arrow; ALT + right-arrow (Win)<br>
    257       CTRL + left-arrow; CTRL + right-arrow (Mac)</td>
    258 </tr>
    259 
    260 </table>
    261 
    262 <p>For a complete keymap reference guide, see the
    263 <a href="http://www.jetbrains.com/idea/documentation/index.jsp">IntelliJ IDEA</a>
    264 documentation.</p>
    265