欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2013年11月12日 16:25:13   作者:  
本文講的是如何修改Android App樣式風(fēng)格的方法,具體可以看下面的代碼
android中可以自定義主題和風(fēng)格。風(fēng)格,也就是style,我們可以將一些統(tǒng)一的屬性拿出來,比方說,長(zhǎng),寬,字體大小,字體顏色等等。可以在res/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è)父類屬性parent, 這個(gè)屬性是說明當(dāng)前的這個(gè)style是繼承自那個(gè)style的,當(dāng)然這個(gè)style的屬性值中都包含那個(gè)屬性中的,你也可以修改繼承到的屬性的值,好了,style完成了,我們可以測(cè)試一下效果了,先寫一個(gè)布局文件,比如說一個(gè)TextView什么的,可以用到這個(gè)style的。這里我就寫一個(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>

說完了style,下面就說說Theme,Theme跟style差不多,但是Theme是應(yīng)用在Application或者Activity里面的,而Style是應(yīng)用在某一個(gè)View里面的,還是有區(qū)別的,好了,廢話不多說,還是看代碼吧。下面的是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è)父類屬性parent, 這個(gè)屬性是說明當(dāng)前的這個(gè)style是繼承自那個(gè)style的,當(dāng)然這個(gè)style的屬性值中都包含那個(gè)屬性中的,你也可以修改繼承到的屬性的值,好了,style完成了,我們可以測(cè)試一下效果了,先寫一個(gè)布局文件,比如說一個(gè)TextView什么的,可以用到這個(gè)style的。這里我就寫一個(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>

說完了style,下面就說說Theme,Theme跟style差不多,但是Theme是應(yīng)用在Application或者Activity里面的,而Style是應(yīng)用在某一個(gè)View里面的,還是有區(qū)別的,好了,廢話不多說,還是看代碼吧。下面的是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>

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

上面的代碼沒有標(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)論