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

修改Android應(yīng)用的樣式的一些關(guān)鍵點(diǎn)解析

 更新時(shí)間:2015年12月01日 16:28:32   投稿:goldensun  
這篇文章主要介紹了修改Android應(yīng)用的樣式的一些關(guān)鍵點(diǎn),即對(duì)影響外觀的theme跟style的相關(guān)修改,需要的朋友可以參考下

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)的值就是屬性的值,如下所示:

<?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吧。下面是布局文件:

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

<?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。

<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è)置主題:

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)論

临海市| 南京市| 喀喇沁旗| 盐城市| 昔阳县| 互助| 汉阴县| 宝坻区| 全南县| 海晏县| 陕西省| 邢台县| 景宁| 汕尾市| 麻江县| 简阳市| 竹北市| 囊谦县| 阳曲县| 温泉县| 枣强县| 梨树县| 蕲春县| 巧家县| 瑞金市| 遵义县| 宁阳县| 锡林郭勒盟| 长治市| 汝城县| 曲松县| 公主岭市| 芦溪县| 武山县| 保靖县| 武夷山市| 无锡市| 西畴县| 伊通| 金昌市| 诏安县|