導航:首頁 > APP軟體 > 安卓stylexml

安卓stylexml

發布時間:2024-06-14 04:53:05

Ⅰ 如何修改Android App的樣式風格

android中可以自定義主題和風格。風格,也就是style,我們可以將一些統一的屬性拿出來,比方說,長,寬,字體大小,字體顏色等等。可以在res/values目錄下新建一個styles.xml的文件,在這個文件裡面有resource根節點,在根節點裡面添加item項,item項的名字就是屬性的名字,item項的值就是屬性的值,如下所示:
復制代碼 代碼如下:

<?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中有一個父類屬性parent, 這個屬性是說明當前的這個style是繼承自那個style的,當然這個style的屬性值中都包含那個屬性中的,你也可以修改繼承到的屬性的值,好了,style完成了,我們可以測試一下效果了,先寫一個布局文件,比如說一個TextView什麼的,可以用到這個style的。這里我就寫一個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="測試一下下"/>
</LinearLayout>

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

style中有一個父類屬性parent, 這個屬性是說明當前的這個style是繼承自那個style的,當然這個style的屬性值中都包含那個屬性中的,你也可以修改繼承到的屬性的值,好了,style完成了,我們可以測試一下效果了,先寫一個布局文件,比如說一個TextView什麼的,可以用到這個style的。這里我就寫一個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="測試一下下"/>
</LinearLayout>

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

可以看到這里寫了一個繼承自系統默認的Theme的主題,裡面有3個屬性,這里強調一下第三個屬性的值的問題,這里打個問號,然後加前面的一個item的名字表示引用的是那個名字的值,也就是那個名字對應的圖片。
然後我們在Manifest.xml裡面的Application裡面加一個Theme的屬性,這個屬性對應的就是我們上面寫的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>

上面的代碼沒有標題欄,背景和fram都是我們設置的圖片。當然也可以在代碼中設置主題:
復制代碼 代碼如下:

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);
}
}

Ⅱ Android婧愮爜鐨刣ata/res/values/style.xml涓鐨勭枒闂

琛ㄦ槑緇ф壙錛岄棶鍙鳳紵琛ㄦ槑浜嗘垜浠寮曠敤鐨勮祫婧愮殑鍊煎湪褰撳墠鐨勪富棰樺綋涓瀹氫箟榪囷紝榪樻湁涓涓狜絎﹀彿錛岃〃鏄庝簡鎴戜滑搴旂敤鐨勮祫婧愭槸鍓嶈竟瀹氫箟榪囩殑鎴栬呭湪鍓嶄竴涓欏圭洰涓鎴栬呭湪Android 妗嗘灦涓瀹氫箟榪囩殑銆

Ⅲ Android欏圭洰涓璿alues-v11values-v14鏂囦歡澶圭殑style.xml鏄浠涔堜綔鐢錛

values-v11浠h〃鍦ˋPI 11+鐨勮懼囦笂錛岀敤璇ョ洰褰曚笅鐨剆tyles.xml浠f浛res/values/styles.xml,鍏朵腑API 11+浠h〃android 3.0 +銆

values-v14浠h〃鍦ˋPI 14+鐨勮懼囦笂錛岀敤璇ョ洰褰曚笅鐨剆tyles.xml浠f浛res/values/styles.xml錛屽叾涓瑼PI 14+浠h〃android 4.0 +銆



Ⅳ 為android程序設置統一的背景圖

這么久了,還是給個明確答案吧
styles.xml:
<style name="AppTheme" parent="AppBaseTheme">

<!-- All customizations that are NOT specific to a particular API-level can go here. -->

<item name="android:windowAnimationStyle">@style/animationActivity</item>

<item name="android:windowBackground">@drawable/dt_bg</item>你自己的圖片設置在這里

</style>

AndroidManifest.xml中版Application設置theme
<application

android:theme="@style/AppTheme" >
運行項目權便出現你想要的背景

閱讀全文

與安卓stylexml相關的資料

熱點內容
編程圖元屬性怎麼修改 瀏覽:828
word文檔的大括弧怎麼輸入 瀏覽:862
關於旅遊收入的數據從哪裡找 瀏覽:989
gson解析json集合問題 瀏覽:680
安卓ipsec標識符填什麼 瀏覽:215
在哪裡解壓文件第一分卷 瀏覽:63
奧維使用教程 瀏覽:324
編程程序怎麼轉到plc上 瀏覽:807
文件名沖突但是找不到 瀏覽:261
上海瑞金醫院app下載 瀏覽:998
qq群里的機器人買武器 瀏覽:428
捕魚達人歷史版本 瀏覽:73
mp4視頻文件解密軟體 瀏覽:62
多軸編程哪個軟體最方便 瀏覽:27
老平板哪個是顯示屏數據線插座 瀏覽:849
5sing上傳音頻文件格式 瀏覽:171
win10輸入文件滑鼠右鍵異常 瀏覽:634
聽幼兒故事用什麼app 瀏覽:514
iphone修改音頻文件名 瀏覽:53
國家氣象站點數據在哪裡下載 瀏覽:342

友情鏈接