修改Android App樣式風(fēng)格的方法
更新時間:2013年11月12日 16:25:13 作者:
本文講的是如何修改Android App樣式風(fēng)格的方法,具體可以看下面的代碼
android中可以自定義主題和風(fēng)格。風(fēng)格,也就是style,我們可以將一些統(tǒng)一的屬性拿出來,比方說,長,寬,字體大小,字體顏色等等??梢栽趓es/values目錄下新建一個styles.xml的文件,在這個文件里面有resource根節(jié)點,在根節(jié)點里面添加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, 這個屬性是說明當(dāng)前的這個style是繼承自那個style的,當(dāng)然這個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是應(yīng)用在Application或者Activity里面的,而Style是應(yīng)用在某一個View里面的,還是有區(qū)別的,好了,廢話不多說,還是看代碼吧。下面的是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, 這個屬性是說明當(dāng)前的這個style是繼承自那個style的,當(dāng)然這個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是應(yīng)用在Application或者Activity里面的,而Style是應(yīng)用在某一個View里面的,還是有區(qū)別的,好了,廢話不多說,還是看代碼吧。下面的是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>
可以看到這里寫了一個繼承自系統(tǒng)默認(rèn)的Theme的主題,里面有3個屬性,這里強(qiáng)調(diào)一下第三個屬性的值的問題,這里打個問號,然后加前面的一個item的名字表示引用的是那個名字的值,也就是那個名字對應(yīng)的圖片。
然后我們在Manifest.xml里面的Application里面加一個Theme的屬性,這個屬性對應(yīng)的就是我們上面寫的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>
上面的代碼沒有標(biāo)題欄,背景和fram都是我們設(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);
}
}
復(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中有一個父類屬性parent, 這個屬性是說明當(dāng)前的這個style是繼承自那個style的,當(dāng)然這個style的屬性值中都包含那個屬性中的,你也可以修改繼承到的屬性的值,好了,style完成了,我們可以測試一下效果了,先寫一個布局文件,比如說一個TextView什么的,可以用到這個style的。這里我就寫一個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="測試一下下"/>
</LinearLayout>
說完了style,下面就說說Theme,Theme跟style差不多,但是Theme是應(yīng)用在Application或者Activity里面的,而Style是應(yīng)用在某一個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中有一個父類屬性parent, 這個屬性是說明當(dāng)前的這個style是繼承自那個style的,當(dāng)然這個style的屬性值中都包含那個屬性中的,你也可以修改繼承到的屬性的值,好了,style完成了,我們可以測試一下效果了,先寫一個布局文件,比如說一個TextView什么的,可以用到這個style的。這里我就寫一個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="測試一下下"/>
</LinearLayout>
說完了style,下面就說說Theme,Theme跟style差不多,但是Theme是應(yīng)用在Application或者Activity里面的,而Style是應(yīng)用在某一個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>
可以看到這里寫了一個繼承自系統(tǒng)默認(rèn)的Theme的主題,里面有3個屬性,這里強(qiáng)調(diào)一下第三個屬性的值的問題,這里打個問號,然后加前面的一個item的名字表示引用的是那個名字的值,也就是那個名字對應(yīng)的圖片。
然后我們在Manifest.xml里面的Application里面加一個Theme的屬性,這個屬性對應(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都是我們設(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);
}
}
您可能感興趣的文章:
- Android自定義狀態(tài)欄顏色與APP風(fēng)格保持一致的實現(xiàn)方法
- Android使用Dialog風(fēng)格彈出框的Activity
- 總結(jié)Android中MD風(fēng)格相關(guān)控件
- Android UI設(shè)計系列之自定義Dialog實現(xiàn)各種風(fēng)格的對話框效果(7)
- Android App仿QQ制作Material Design風(fēng)格沉浸式狀態(tài)欄
- Android2.3實現(xiàn)Android4.0風(fēng)格EditText的方法
- Android自定義ViewGroup打造各種風(fēng)格的SlidingMenu
- android底部彈出iOS7風(fēng)格對話選項框(QQ對話框)--第三方開源之IOS_Dialog_Library
- Android Studio設(shè)置主題與字體大小圖文教程
- Android入門教程之創(chuàng)建樣式與主題
- 分析Android多主題顏色的相關(guān)問題
- Android主題切換之探究白天和夜間模式
- 基于android樣式與主題(style&theme)的詳解
- Android中應(yīng)用界面主題Theme使用方法和頁面定時跳轉(zhuǎn)應(yīng)用
- Android編程應(yīng)用風(fēng)格和主題詳解
相關(guān)文章
Android ViewDragHelper實現(xiàn)京東、淘寶拖拽詳情功能的實現(xiàn)
這篇文章主要介紹了Android ViewDragHelper實現(xiàn)京東、淘寶拖拽詳情,實現(xiàn)這種效果大概分為三種方式,具體哪三種方式大家通過本文了解下吧2018-04-04淺談Android開發(fā)者2017年最值得關(guān)注的25個實用庫
本篇文章主要介紹了Android開發(fā)者2017年最值得關(guān)注的25個庫,非常具有實用價值,需要的朋友可以參考下2017-09-09Android通過SharedPreferences實現(xiàn)自動登錄記住用戶名和密碼功能
最近使用SharedPreferences實現(xiàn)了一個android自動登錄功能,特此分享到腳本之家平臺供大家參考2017-07-07Android自定義View實現(xiàn)圓弧進(jìn)度效果逐步完成過程
在Android開發(fā)中,通過自定義View實現(xiàn)自己想要的效果是作為android開發(fā)程序員的一項必備技能,自定義View對于android開發(fā)來說也是比較難的一項技術(shù)2023-04-04Flutter利用Hero組件實現(xiàn)自定義路徑效果的動畫
本篇介紹了如何利用Hero動畫組件的createRectTween屬性實現(xiàn)自定義路徑效果的動畫。文中的示例代碼講解詳細(xì),感興趣的可以了解一下2022-06-06如何在Android中實現(xiàn)漸顯按鈕的左右滑動效果
本篇文章是對在Android中實現(xiàn)漸顯按鈕的左右滑動效果進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06android 仿微信demo——微信消息界面實現(xiàn)(服務(wù)端)
本系列文章主要介紹了微信小程序-閱讀小程序?qū)嵗╠emo),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧,希望能給你們提供幫助2021-06-06