最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

修改Android App樣式風(fēng)格的方法

 更新時(shí)間:2013年11月12日 16:25:13   作者:  
本文講的是如何修改Android App樣式風(fēng)格的方法,具體可以看下面的代碼
android中可以自定義主題和風(fēng)格。風(fēng)格,也就是style,我們可以將一些統(tǒng)一的屬性拿出來(lái),比方說(shuō),長(zhǎng),寬,字體大小,字體顏色等等??梢栽趓es/values目錄下新建一個(gè)styles.xml的文件,在這個(gè)文件里面有resource根節(jié)點(diǎn),在根節(jié)點(diǎn)里面添加item項(xiàng),item項(xiàng)的名字就是屬性的名字,item項(xiàng)的值就是屬性的值,如下所示:
復(fù)制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>
 <style name="MyText" parent="@android:style/TextAppearance">
     <item name="android:textColor">#987456</item>
  <item name="android:textSize">24sp</item>
 </style>
</resources>

style中有一個(gè)父類(lèi)屬性parent, 這個(gè)屬性是說(shuō)明當(dāng)前的這個(gè)style是繼承自那個(gè)style的,當(dāng)然這個(gè)style的屬性值中都包含那個(gè)屬性中的,你也可以修改繼承到的屬性的值,好了,style完成了,我們可以測(cè)試一下效果了,先寫(xiě)一個(gè)布局文件,比如說(shuō)一個(gè)TextView什么的,可以用到這個(gè)style的。這里我就寫(xiě)一個(gè)EditText吧。下面是布局文件:
復(fù)制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent">
<EditText
 android:id="@+id/myEditText"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 style="@style/MyText"
 android:text="測(cè)試一下下"/>
</LinearLayout>

說(shuō)完了style,下面就說(shuō)說(shuō)Theme,Theme跟style差不多,但是Theme是應(yīng)用在A(yíng)pplication或者Activity里面的,而Style是應(yīng)用在某一個(gè)View里面的,還是有區(qū)別的,好了,廢話(huà)不多說(shuō),還是看代碼吧。下面的是style文件:
復(fù)制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>
 <style name="MyText" parent="@android:style/TextAppearance">
  <item name="android:textColor">#987456</item>
  <item name="android:textSize">24sp</item>
 </style>
 <style parent="@android:style/Theme" name="CustomTheme">
  <item name="android:windowNoTitle">true</item>
  <item name="android:windowFrame">@drawable/icon</item>
  <item name="android:windowBackground">?android:windowFrame</item>
</style>
</resources>

style中有一個(gè)父類(lèi)屬性parent, 這個(gè)屬性是說(shuō)明當(dāng)前的這個(gè)style是繼承自那個(gè)style的,當(dāng)然這個(gè)style的屬性值中都包含那個(gè)屬性中的,你也可以修改繼承到的屬性的值,好了,style完成了,我們可以測(cè)試一下效果了,先寫(xiě)一個(gè)布局文件,比如說(shuō)一個(gè)TextView什么的,可以用到這個(gè)style的。這里我就寫(xiě)一個(gè)EditText吧。下面是布局文件:
復(fù)制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent">
<EditText
 android:id="@+id/myEditText"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 style="@style/MyText"
 android:text="測(cè)試一下下"/>
</LinearLayout>

說(shuō)完了style,下面就說(shuō)說(shuō)Theme,Theme跟style差不多,但是Theme是應(yīng)用在A(yíng)pplication或者Activity里面的,而Style是應(yīng)用在某一個(gè)View里面的,還是有區(qū)別的,好了,廢話(huà)不多說(shuō),還是看代碼吧。下面的是style文件:
復(fù)制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>
 <style name="MyText" parent="@android:style/TextAppearance">
  <item name="android:textColor">#987456</item>
  <item name="android:textSize">24sp</item>
 </style>
 <style parent="@android:style/Theme" name="CustomTheme">
  <item name="android:windowNoTitle">true</item>
  <item name="android:windowFrame">@drawable/icon</item>
  <item name="android:windowBackground">?android:windowFrame</item>
</style>
</resources>

可以看到這里寫(xiě)了一個(gè)繼承自系統(tǒng)默認(rèn)的Theme的主題,里面有3個(gè)屬性,這里強(qiáng)調(diào)一下第三個(gè)屬性的值的問(wèn)題,這里打個(gè)問(wèn)號(hào),然后加前面的一個(gè)item的名字表示引用的是那個(gè)名字的值,也就是那個(gè)名字對(duì)應(yīng)的圖片。
然后我們?cè)贛anifest.xml里面的Application里面加一個(gè)Theme的屬性,這個(gè)屬性對(duì)應(yīng)的就是我們上面寫(xiě)的Theme。
復(fù)制代碼 代碼如下:

<application android:icon="@drawable/icon" android:label="@string/app_name"
 android:theme="@style/CustomTheme">
<activity android:name=".TestStyle"
 android:label="@string/app_name">
<intent-filter>
 <action android:name="android.intent.action.MAIN" />
 <category android:name="android.intent.category.LAUNCHER" />
 </intent-filter>
</activity>

上面的代碼沒(méi)有標(biāo)題欄,背景和fram都是我們?cè)O(shè)置的圖片。當(dāng)然也可以在代碼中設(shè)置主題:
復(fù)制代碼 代碼如下:

package com.test.shang;
import android.app.Activity;
import android.os.Bundle;
public class TestStyle extends Activity {
 @Override
 protected void onCreate (Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setTheme(R.style.CustomTheme);
  setContentView(R.layout.test_style);
 }
}

相關(guān)文章

最新評(píng)論

申扎县| 漠河县| 翁牛特旗| 汾西县| 丽水市| 罗定市| 新和县| 东辽县| 壤塘县| 石屏县| 古田县| 建昌县| 平泉县| 辽宁省| 化州市| 合作市| 民乐县| 平塘县| 新泰市| 延津县| 桃园县| 同德县| 黎平县| 方山县| 台南县| 砀山县| 咸阳市| 北宁市| 荥阳市| 谢通门县| 盐亭县| 广东省| 体育| 岳池县| 兰坪| 长汀县| 乌恰县| 乡宁县| 阿鲁科尔沁旗| 蓝山县| 横峰县|