修改Android App樣式風(fē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>
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);
}
}
- Android自定義狀態(tài)欄顏色與APP風(fēng)格保持一致的實(shí)現(xiàn)方法
- Android使用Dialog風(fēng)格彈出框的Activity
- 總結(jié)Android中MD風(fēng)格相關(guān)控件
- Android UI設(shè)計(jì)系列之自定義Dialog實(shí)現(xiàn)各種風(fēng)格的對(duì)話(huà)框效果(7)
- Android App仿QQ制作Material Design風(fēng)格沉浸式狀態(tài)欄
- Android2.3實(shí)現(xiàn)Android4.0風(fēng)格EditText的方法
- Android自定義ViewGroup打造各種風(fēng)格的SlidingMenu
- android底部彈出iOS7風(fēng)格對(duì)話(huà)選項(xiàng)框(QQ對(duì)話(huà)框)--第三方開(kāi)源之IOS_Dialog_Library
- Android Studio設(shè)置主題與字體大小圖文教程
- Android入門(mén)教程之創(chuàng)建樣式與主題
- 分析Android多主題顏色的相關(guān)問(wèn)題
- Android主題切換之探究白天和夜間模式
- 基于android樣式與主題(style&theme)的詳解
- Android中應(yīng)用界面主題Theme使用方法和頁(yè)面定時(shí)跳轉(zhuǎn)應(yīng)用
- Android編程應(yīng)用風(fēng)格和主題詳解
相關(guān)文章
Android ListView position詳解及實(shí)例代碼
這篇文章主要介紹了Android ListView position的相關(guān)資料,在開(kāi)發(fā)Android 應(yīng)用的時(shí)候你真的用對(duì)了嗎?這里給大家徹底解釋下,需要的朋友可以參考下2016-10-10
Android 使用地圖時(shí)的權(quán)限請(qǐng)求方法
今天小編就為大家分享一篇Android 使用地圖時(shí)的權(quán)限請(qǐng)求方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-07-07
ScrollView嵌套ListView滑動(dòng)沖突的解決方法
這篇文章主要介紹了ScrollView嵌套ListView滑動(dòng)沖突的解決方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-11-11
Android開(kāi)發(fā)中R.java文件丟失或無(wú)法更新的解決方法
這篇文章主要介紹了Android開(kāi)發(fā)中R.java文件丟失或無(wú)法更新的解決方法,較為詳細(xì)的列舉分析了出現(xiàn)R.java文件丟失或無(wú)法更新的常見(jiàn)原因及相應(yīng)的解決方法,需要的朋友可以參考下2016-02-02
Android TabLayout實(shí)現(xiàn)京東詳情效果
這篇文章主要為大家詳細(xì)介紹了android TabLayout實(shí)現(xiàn)京東詳情效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09
Android?通過(guò)productFlavors實(shí)現(xiàn)多渠道打包方法示例
這篇文章主要為大家介紹了Android?通過(guò)productFlavors實(shí)現(xiàn)多渠道打包方法示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02
android studio按鈕監(jiān)聽(tīng)的5種方法實(shí)例詳解
這篇文章主要介紹了android studio按鈕監(jiān)聽(tīng)的5種方法,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03
Android模擬器安裝APP出現(xiàn)INSTALL_FAILED_NO_MATCHING_ABIS錯(cuò)誤解決方案
這篇文章主要介紹了 Android模擬器安裝APP出現(xiàn)INSTALL_FAILED_NO_MATCHING_ABIS錯(cuò)誤解決方案的相關(guān)資料,需要的朋友可以參考下2016-12-12

