Home | History | Annotate | Download | only in material
      1 page.title=Duy tr Tnh tng thch
      2 
      3 @jd:body
      4 
      5 <div id="tb-wrapper">
      6 <div id="tb">
      7 <h2>Bi hc ny hng dn bn cch</h2>
      8 <ol>
      9   <li><a href="#Theme">nh ngha Kiu Thay th</a></li>
     10   <li><a href="#Layouts">Cung cp B tr Thay th</a></li>
     11   <li><a href="#SupportLib">S dng Th vin H tr</a></li>
     12   <li><a href="#CheckVersion">Kim tra Phin bn H thng</a></li>
     13 </ol>
     14 <h2>Bn cng nn c</h2>
     15 <ul>
     16   <li><a href="http://www.google.com/design/spec">c t phong cch Material Design</a></li>
     17   <li><a href="{@docRoot}design/material/index.html">Material Design trn Android</a></li>
     18 </ul>
     19 </div>
     20 </div>
     21 
     22 
     23 <p>Mt s tnh nng ca Material Design nh ch  Material v chuyn tip hot ng ty chnh
     24 ch sn c trn Android 5.0 (API mc 21) tr ln. Tuy nhin, bn c th thit k ng dng ca mnh  tn dng
     25 nhng tnh nng ny khi chy trn thit b h tr material design m vn tng thch
     26 vi thit b ang chy cc bn pht hnh Android trc y.</p>
     27 
     28 
     29 <h2 id="Theme">nh ngha Kiu Thay th</h2>
     30 
     31 <p>Bn c th cu hnh ng dng ca mnh  s dng ch  material trn nhng thit b h tr v chuyn v
     32 ch  c hn trn nhng thit b ang chy phin bn Android c hn:</p>
     33 
     34 <ol>
     35 <li>nh ngha mt ch  k tha t mt ch  c hn (nh Holo) trong
     36     <code>res/values/styles.xml</code>.</li>
     37 <li>nh ngha mt ch  vi cng tn v k tha ch  material trong
     38     <code>res/values-v21/styles.xml</code>.</li>
     39 <li>t ch  ny lm ch  cho ng dng ca bn trong tp bn k khai.</li>
     40 </ol>
     41 
     42 <p class="note"><strong>Lu :</strong>
     43 Nu ng dng ca bn s dng ch  material nhng khng cung cp ch  thay th bng cch ny,
     44 ng dng ca bn s khng chy trn phin bn Android trc 5.0.
     45 </p>
     46 
     47 
     48 <h2 id="Layouts">Cung cp B tr Thay th</h2>
     49 
     50 <p>Nu nhng b tr m bn thit k theo hng dn v material design khng s dng bt c
     51 thuc tnh XML mi no c gii thiu trong Android 5.0 (API mc 21), chng s hot ng trn cc phin bn
     52 Android trc . Nu khng, bn c th cung cp b tr thay th. Bn cng c th cung cp
     53 b tr thay th  ty chnh din mo ng dng ca mnh trn cc phin bn Android c hn.</p>
     54 
     55 <p>To tp b tr ca bn cho Android 5.0 (API mc 21) bn trong <code>res/layout-v21/</code> v
     56 tp b tr thay th ca bn cho cc phin bn Android c hn trong <code>res/layout/</code>.
     57 V d, <code>res/layout/my_activity.xml</code> l mt b tr thay th cho
     58 <code>res/layout-v21/my_activity.xml</code>.</p>
     59 
     60 <p> trnh lp m, hy nh ngha kiu ca bn bn trong <code>res/values/</code>, sa i
     61 cc kiu trong <code>res/values-v21/</code> cho cc API mi v s dng k tha kiu, nh ngha
     62 kiu c bn trong <code>res/values/</code> v k tha t nhng kiu trong <code>res/values-v21/</code>.</p>
     63 
     64 
     65 <h2 id="SupportLib">S dng Th vin H tr</h2>
     66 
     67 <p><a href="{@docRoot}tools/support-library/features.html#v7">Th vin H tr v7</a>
     68 r21 v cao hn gm nhng tnh nng material design sau:</p>
     69 
     70 <ul>
     71 <li><a href="{@docRoot}training/material/theme.html">Cc kiu mang phong cch material design</a> cho mt s widget
     72     h thng khi bn p dng mt trong cc ch  <code>Theme.AppCompat</code>.</li>
     73 <li><a href="{@docRoot}training/material/theme.html#ColorPalette">Thuc tnh ch  bng mu</a>
     74    trong cc ch  <code>Theme.AppCompat</code>.</li>
     75 <li>Widget {@link android.support.v7.widget.RecyclerView}  <a href="{@docRoot}training/material/lists-cards.html#RecyclerView">hin th cc b su tp
     76     d liu</a>.</li>
     77 <li>Widget {@link android.support.v7.widget.CardView}  <a href="{@docRoot}training/material/lists-cards.html#CardView">to th</a>.</li>
     78 <li>Lp {@link android.support.v7.graphics.Palette}  <a href="{@docRoot}training/material/drawables.html#ColorExtract">trch xut mu ni bt t
     79     hnh nh</a>.</li>
     80 </ul>
     81 
     82 <h3>Widget h thng</h3>
     83 
     84 <p>Ch  <code>Theme.AppCompat</code> cung cp cc kiu phong cch material design cho nhng widget ny:</p>
     85 
     86 <ul>
     87   <li>{@link android.widget.EditText}</li>
     88   <li>{@link android.widget.Spinner}</li>
     89   <li>{@link android.widget.CheckBox}</li>
     90   <li>{@link android.widget.RadioButton}</li>
     91   <li>{@link android.support.v7.widget.SwitchCompat}</li>
     92   <li>{@link android.widget.CheckedTextView}</li>
     93 </ul>
     94 
     95 <h3>Bng mu</h3>
     96 
     97 <p> c c cc kiu phong cch material design v ty chnh bng mu bng Th vin H tr v7 
     98 ca Android, hy p dng mt trong cc ch  <code>Theme.AppCompat</code>:</p>
     99 
    100 <pre>
    101 &lt;!-- extend one of the Theme.AppCompat themes -->
    102 &lt;style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
    103     &lt;!-- customize the color palette -->
    104     &lt;item name="colorPrimary">@color/material_blue_500&lt;/item>
    105     &lt;item name="colorPrimaryDark">@color/material_blue_700&lt;/item>
    106     &lt;item name="colorAccent">@color/material_green_A200&lt;/item>
    107 &lt;/style>
    108 </pre>
    109 
    110 <h3>Danh sch v Th</h3>
    111 
    112 <p>Widget {@link android.support.v7.widget.RecyclerView} v {@link
    113 android.support.v7.widget.CardView} sn c trong cc phin bn Android c hn thng qua
    114 Th vin H tr v7 ca Android vi nhng hn ch sau:</p>
    115 <ul>
    116 <li>{@link android.support.v7.widget.CardView} quay li trin khai  bng theo lp trnh
    117     bng cch s dng phn m b sung.</li>
    118 <li>{@link android.support.v7.widget.CardView} khng ct hnh nhng dng xem con ca n c giao ct vi
    119     cc gc bo trn.</li>
    120 </ul>
    121 
    122 
    123 <h3>Ph thuc</h3>
    124 
    125 <p> s dng nhng tnh nng ny trong cc phin bn Android trc 5.0 (API mc 21), hy thm
    126 Th vin H tr v7 ca Android vo d n ca bn nh mt <a href="{@docRoot}sdk/installing/studio-build.html#dependencies">Phn ph thuc Gradle</a>:</p>
    127 
    128 <pre>
    129 dependencies {
    130     compile 'com.android.support:appcompat-v7:21.0.+'
    131     compile 'com.android.support:cardview-v7:21.0.+'
    132     compile 'com.android.support:recyclerview-v7:21.0.+'
    133 }
    134 </pre>
    135 
    136 
    137 <h2 id="CheckVersion">Kim tra Phin bn H thng</h2>
    138 
    139 <p>Nhng tnh nng sau ch sn c trong Android 5.0 (API mc 21) tr ln:</p>
    140 
    141 <ul>
    142 <li>Chuyn tip hot ng</li>
    143 <li>Phn hi chm</li>
    144 <li>L ra hot hnh</li>
    145 <li>Hot hnh da trn ng dn</li>
    146 <li>Ni dung v c vc-t</li>
    147 <li>Nhum mu ni dung v c</li>
    148 </ul>
    149 
    150 <p> duy tr tnh tng thch vi cc phin bn Android c hn, hy kim tra {@link
    151 android.os.Build.VERSION#SDK_INT version} vo thi gian chy trc khi bn gi ra API cho bt c tnh nng no
    152 sau y:</p>
    153 
    154 <pre>
    155 // Check if we're running on Android 5.0 or higher
    156 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    157     // Call some material design APIs here
    158 } else {
    159     // Implement this feature without material design
    160 }
    161 </pre>
    162 
    163 <p class="note"><strong>Lu :</strong>  quy nh ng dng ca bn h tr nhng phin bn Android no,
    164 hy s dng thuc tnh <code>android:minSdkVersion</code> v <code>android:targetSdkVersion</code>
    165 trong tp bn k khai ca bn.  s dng cc tnh nng ca material design trong Android 5.0, hy t
    166 thuc tnh <code>android:targetSdkVersion</code> thnh <code>21</code>.  bit thm thng tin, hy xem hng dn
    167  <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html">&lt;uses-sdk&gt; API
    168 </a>.</p>
    169