修改Android應(yīng)用的樣式的一些關(guān)鍵點(diǎ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)用在A(yíng)pplication或者Activity里面的,而Style是應(yīng)用在某一個(gè)View里面的,還是有區(qū)別的,好了,廢話(huà)不多說(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)文章
spring boot啟動(dòng)出現(xiàn)Unable to start ServletWe
在使用SpringBoot時(shí),啟動(dòng)報(bào)錯(cuò)可能源于多種原因,錯(cuò)誤提示為缺少ServletWebServerFactory bean,初步分析可能是缺少spring-boot-starter-web依賴(lài)或@EnableAutoConfiguration注解,感興趣的可以了解一下2024-10-10
劍指Offer之Java算法習(xí)題精講數(shù)組查找與字符串交集
跟著思路走,之后從簡(jiǎn)單題入手,反復(fù)去看,做過(guò)之后可能會(huì)忘記,之后再做一次,記不住就反復(fù)做,反復(fù)尋求思路和規(guī)律,慢慢積累就會(huì)發(fā)現(xiàn)質(zhì)的變化2022-03-03
MybatisPlus分頁(yè)查詢(xún)與多條件查詢(xún)介紹及查詢(xún)過(guò)程中空值問(wèn)題的解決
mybatisplus是個(gè)很好用的插件,相信小伙伴們都知道,下面這篇文章主要給大家介紹了關(guān)于mybatis-plus實(shí)現(xiàn)分頁(yè)查詢(xún)與多條件查詢(xún)介紹及查詢(xún)過(guò)程中空值問(wèn)題的相關(guān)資料,需要的朋友可以參考下2022-10-10
java多線(xiàn)程中的volatile和synchronized用法分析
這篇文章主要介紹了java多線(xiàn)程中的volatile和synchronized用法分析,以實(shí)例的形式分析了在多線(xiàn)程中volatile和synchronized的用法區(qū)別與使用原理,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2014-12-12
使用游長(zhǎng)編碼對(duì)字符串壓縮 Run Length編碼示例
這篇文章主要介紹了Run Length編碼的一個(gè)示例,大家參考使用吧2014-01-01
form-data與x-www-form-urlencoded的區(qū)別以及知識(shí)延伸
這篇文章主要給大家介紹了關(guān)于form-data與x-www-form-urlencoded的區(qū)別以及知識(shí)延伸,form-data和x-www-form-urlencoded都是HTTP請(qǐng)求中用于傳輸表單數(shù)據(jù)的編碼格式,需要的朋友可以參考下2023-11-11

