Home | History | Annotate | Download | only in resources
      1 page.title=
      2 parent.title= 
      3 parent.link=index.html
      4 @jd:body
      5 
      6 <div id="qv-wrapper">
      7 <div id="qv">
      8   <h2></h2>
      9   <ul>
     10     <li>{@code R.java} {@code R.drawable.myimage} 
     11 </li>
     12     <li> XML {@code
     13 &#64;drawable/myimage} </li>
     14     <li>{@link android.content.res.Resources}  
     15 </li>
     16   </ul>
     17 
     18   <h2></h2>
     19   <ol>
     20     <li>{@link android.content.res.Resources}</li>
     21   </ol>
     22 
     23   <h2></h2>
     24   <ol>
     25     <li><a href="#ResourcesFromCode"></a></li>
     26     <li><a href="#ResourcesFromXml">XML </a>
     27       <ol>
     28         <li><a href="#ReferencesToThemeAttributes"></a></li>
     29       </ol>
     30     </li>
     31     <li><a href="#PlatformResources"> </a></li>
     32   </ol>
     33 
     34   <h2></h2>
     35   <ol>
     36     <li><a href="providing-resources.html"></a></li>
     37     <li><a href="available-resources.html">Resource Types</a></li>
     38   </ol>
     39 </div>
     40 </div>
     41 
     42 
     43 
     44 
     45 <p><a href="providing-resources.html"></a> ID  ID  {@code R}  {@code aapt} 
     46 
     47 </p>
     48 
     49 <p>{@code aapt}  {@code R} {@code
     50 res/}  ID 
     51 {@code R} :   {@code R.drawable}: {@code R.drawable.icon}
     52 
     53  ID 
     54 </p>
     55 
     56 <p>{@code R}  ID  ID  ID 
     57 </p>
     58 <ul>
     59   <li><em></em>: {@code
     60 string}{@code drawable}{@code layout} <a href="available-resources.html">Resource Types</a>
     61   </li>
     62   <li><em></em>XML {@code android:name} 
     63 
     64 </li>
     65 </ul>
     66 
     67 <p> 2 </p>
     68 <ul>
     69   <li><strong>:</strong> {@code R} 
     70 
     71     <pre class="classic no-pretty-print">R.string.hello</pre>
     72     <p>{@code string} {@code hello}  Android API  ID 
     73 <a href="#ResourcesFromCode"></a>
     74 </p>
     75   </li>
     76   <li><strong>XML :</strong> {@code R}  ID  XML 
     77 
     78     <pre class="classic no-pretty-print">&#64;string/hello</pre>
     79     <p>{@code string} {@code hello} XML 
     80 <a href="#ResourcesFromXml">XML </a></p>
     81   </li>
     82 </ul>
     83 
     84 
     85 
     86 <h2 id="ResourcesFromCode"> </h2>
     87 
     88 <p> ID  {@link android.widget.ImageView#setImageResource(int) setImageResource()} {@link android.widget.ImageView}  {@code res/drawable/myimage.png} 
     89 
     90 </p>
     91 <pre>
     92 ImageView imageView = (ImageView) findViewById(R.id.myimageview);
     93 imageView.setImageResource(<strong>R.drawable.myimage</strong>);
     94 </pre>
     95 
     96 <p>{@link
     97 android.content.res.Resources} {@link android.content.Context#getResources()} 
     98 </p>
     99 
    100 <div class="sidebox-wrapper">
    101 <div class="sidebox">
    102 <h2></h2>
    103 
    104 <p>{@code res/}  ID {@code res/} {@code assets/} 
    105 
    106 
    107 </p>
    108 <p>{@code assets/}  ID <em></em>{@code R}  XML 
    109   {@code assets/} {@link android.content.res.AssetManager} 
    110 
    111 </p>
    112 <p> {@code res/raw/} {@link
    113 android.content.res.Resources#openRawResource(int) openRawResource()} 
    114 </p>
    115 
    116 </div>
    117 </div>
    118 
    119 
    120 <h3></h3>
    121 
    122 <p></p>
    123 
    124 <pre class="classic no-pretty-print">
    125 [<em>&lt;package_name&gt;</em>.]R.<em>&lt;resource_type&gt;</em>.<em>&lt;resource_name&gt;</em>
    126 </pre>
    127 
    128 <ul>
    129   <li><em>{@code &lt;package_name&gt;}</em> 
    130 </li>
    131   <li><em>{@code &lt;resource_type&gt;}</em>  {@code R} </li>
    132   <li><em>{@code &lt;resource_name&gt;}</em>  XML  {@code android:name} 
    133 
    134 </li>
    135 </ul>
    136 <p><a href="available-resources.html">Resource Types</a>
    137 </p>
    138 
    139 
    140 <h3></h3>
    141 
    142 <p> ID {@link android.content.res.Resources} 
    143 {@link
    144 android.content.res.Resources} {@link android.content.Context#getResources
    145 Context.getResources()} </p>
    146 
    147 
    148 <p></p>
    149 
    150 <pre>
    151 // Load a background for the current screen from a drawable resource
    152 {@link android.app.Activity#getWindow()}.{@link
    153 android.view.Window#setBackgroundDrawableResource(int)
    154 setBackgroundDrawableResource}(<strong>R.drawable.my_background_image</strong>) ;
    155 
    156 // Set the Activity title by getting a string from the Resources object, because
    157 //  this method requires a CharSequence rather than a resource ID
    158 {@link android.app.Activity#getWindow()}.{@link android.view.Window#setTitle(CharSequence)
    159 setTitle}(getResources().{@link android.content.res.Resources#getText(int)
    160 getText}(<strong>R.string.main_title</strong>));
    161 
    162 // Load a custom layout for the current screen
    163 {@link android.app.Activity#setContentView(int)
    164 setContentView}(<strong>R.layout.main_screen</strong>);
    165 
    166 // Set a slide in animation by getting an Animation from the Resources object
    167 mFlipper.{@link android.widget.ViewAnimator#setInAnimation(Animation)
    168 setInAnimation}(AnimationUtils.loadAnimation(this,
    169         <strong>R.anim.hyperspace_in</strong>));
    170 
    171 // Set the text on a TextView object using a resource ID
    172 TextView msgTextView = (TextView) findViewById(<strong>R.id.msg</strong>);
    173 msgTextView.{@link android.widget.TextView#setText(int)
    174 setText}(<strong>R.string.hello_message</strong>);
    175 </pre>
    176 
    177 
    178 <p class="caution"><strong>:</strong> {@code
    179 R.java} &mdash;{@code aapt} 
    180 </p>
    181 
    182 
    183 
    184 <h2 id="ResourcesFromXml">XML </h2>
    185 
    186 <p> XML 
    187  
    188 </p>
    189 
    190 <p> {@link android.widget.Button} <a href="string-resource.html"></a>
    191 </p>
    192 
    193 <pre>
    194 &lt;Button
    195     android:layout_width="fill_parent"
    196     android:layout_height="wrap_content"
    197     android:text="<strong>@string/submit</strong>" /&gt;
    198 </pre>
    199 
    200 
    201 <h3></h3>
    202 
    203 <p>XML </p>
    204 
    205 <pre class="classic no-pretty-print">
    206 &#64;[<em>&lt;package_name&gt;</em>:]<em>&lt;resource_type&gt;</em>/<em>&lt;resource_name&gt;</em>
    207 </pre>
    208 
    209 <ul>
    210   <li>{@code &lt;package_name&gt;} 
    211 </li>
    212   <li>{@code &lt;resource_type&gt;}  {@code R} 
    213 </li>
    214   <li>{@code &lt;resource_name&gt;}  XML  {@code android:name} 
    215 
    216 </li>
    217 </ul>
    218 
    219 <p><a href="available-resources.html">Resource Types</a>
    220 </p>
    221 
    222 
    223 <h3></h3>
    224 
    225 <p>XML  XML 
    226 <a href="more-resources.html#Color"></a><a href="string-resource.html"></a>
    227 </p>
    228 
    229 <pre>
    230 &lt;?xml version="1.0" encoding="utf-8"?>
    231 &lt;resources>
    232    &lt;color name="opaque_red">#f00&lt;/color>
    233    &lt;string name="hello">Hello!&lt;/string>
    234 &lt;/resources>
    235 </pre>
    236 
    237 <p> 
    238 </p>
    239 
    240 <pre>
    241 &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
    242 &lt;EditText xmlns:android=&quot;http://schemas.android.com/apk/res/android";
    243     android:layout_width=&quot;fill_parent&quot;
    244     android:layout_height=&quot;fill_parent&quot;
    245     android:textColor=&quot;<strong>&#64;color/opaque_red</strong>&quot;
    246     android:text=&quot;<strong>&#64;string/hello</strong>&quot; /&gt;
    247 </pre>
    248 
    249 <p>
    250  
    251 </p>
    252 
    253 <pre>
    254 &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
    255 &lt;EditText xmlns:android=&quot;http://schemas.android.com/apk/res/android";
    256     android:layout_width=&quot;fill_parent&quot;
    257     android:layout_height=&quot;fill_parent&quot;
    258     android:textColor=&quot;<strong>&#64;android:color/secondary_text_dark</strong>&quot;
    259     android:text=&quot;&#64;string/hello&quot; /&gt;
    260 </pre>
    261 
    262 <p class="note"><strong>:</strong> 
    263 <a href="providing-resources.html#AlternativeResources"></a>
    264 
    265 
    266 <a href="localization.html">Localization</a>
    267 </p>
    268 
    269 <p>XML   
    270 </p>
    271 
    272 <pre>
    273 &lt;?xml version="1.0" encoding="utf-8"?>
    274 &lt;bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    275     android:src="@drawable/other_drawable" />
    276 </pre>
    277 
    278 <p><a href="providing-resources.html#AliasResources"> </a>
    279 </p>
    280 
    281 
    282 
    283 <h3 id="ReferencesToThemeAttributes"></h3>
    284 
    285 <p>
    286 UI 
    287 
    288 
    289 </p>
    290 
    291 <p>{@code @}{@code ?}
    292 
    293 : </p>
    294 
    295 <pre class="classic">
    296 ?[<em>&lt;package_name&gt;</em>:][<em>&lt;resource_type&gt;</em>/]<em>&lt;resource_name&gt;</em>
    297 </pre>
    298 
    299 <p>   
    300 </p>
    301 
    302 <pre>
    303 &lt;EditText id=&quot;text&quot;
    304     android:layout_width=&quot;fill_parent&quot;
    305     android:layout_height=&quot;wrap_content&quot;
    306     android:textColor=&quot;<strong>?android:textColorSecondary</strong>&quot;
    307     android:text=&quot;&#64;string/hello_world&quot; /&gt;
    308 </pre>
    309 
    310 <p>{@code android:textColor} 
    311 Android {@code android:textColorSecondary}  {@code android:textColor} 
    312    <code>?android:attr/textColorSecondary</code> &mdash; {@code attr} 
    313 
    314 
    315 </p>
    316 
    317 
    318 
    319 
    320 <h2 id="PlatformResources"> </h2>
    321 
    322 <p>Android <code>android</code> 
    323 
    324 Android {@link android.widget.ListAdapter}  
    325 </p>
    326 
    327 <pre>
    328 {@link android.app.ListActivity#setListAdapter(ListAdapter)
    329 setListAdapter}(new {@link
    330 android.widget.ArrayAdapter}&lt;String&gt;(this, <strong>android.R.layout.simple_list_item_1</strong>, myarray));
    331 </pre>
    332 
    333 <p>{@link android.R.layout#simple_list_item_1}  {@link android.widget.ListView}  
    334 
    335 <a href="{@docRoot}guide/topics/ui/layout/listview.html">List View</a> 
    336 </p>
    337 
    338