修改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è)父類屬性parent, 這個(gè)屬性是說明當(dāng)前的這個(gè)style是繼承自那個(gè)style的,當(dāng)然這個(gè)style的屬性值中都包含那個(gè)屬性中的,你也可以修改繼承到的屬性的值,好了,style完成了,我們可以測(cè)試一下效果了,先寫一個(gè)布局文件,比如說一個(gè)TextView什么的,可以用到這個(gè)style的。這里我就寫一個(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>
說完了style,下面就說說Theme,Theme跟style差不多,但是Theme是應(yīng)用在Application或者Activity里面的,而Style是應(yīng)用在某一個(gè)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中有一個(gè)父類屬性parent, 這個(gè)屬性是說明當(dāng)前的這個(gè)style是繼承自那個(gè)style的,當(dāng)然這個(gè)style的屬性值中都包含那個(gè)屬性中的,你也可以修改繼承到的屬性的值,好了,style完成了,我們可以測(cè)試一下效果了,先寫一個(gè)布局文件,比如說一個(gè)TextView什么的,可以用到這個(gè)style的。這里我就寫一個(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>
說完了style,下面就說說Theme,Theme跟style差不多,但是Theme是應(yīng)用在Application或者Activity里面的,而Style是應(yīng)用在某一個(gè)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>
可以看到這里寫了一個(gè)繼承自系統(tǒng)默認(rèn)的Theme的主題,里面有3個(gè)屬性,這里強(qiáng)調(diào)一下第三個(gè)屬性的值的問題,這里打個(gè)問號(hào),然后加前面的一個(gè)item的名字表示引用的是那個(gè)名字的值,也就是那個(gè)名字對(duì)應(yīng)的圖片。
然后我們?cè)贛anifest.xml里面的Application里面加一個(gè)Theme的屬性,這個(gè)屬性對(duì)應(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都是我們?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ì)話框效果(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ì)話選項(xiàng)框(QQ對(duì)話框)--第三方開源之IOS_Dialog_Library
- Android Studio設(shè)置主題與字體大小圖文教程
- Android入門教程之創(chuàng)建樣式與主題
- 分析Android多主題顏色的相關(guān)問題
- Android主題切換之探究白天和夜間模式
- 基于android樣式與主題(style&theme)的詳解
- Android中應(yīng)用界面主題Theme使用方法和頁面定時(shí)跳轉(zhuǎn)應(yīng)用
- Android編程應(yīng)用風(fēng)格和主題詳解
相關(guān)文章
Android ViewDragHelper實(shí)現(xiàn)京東、淘寶拖拽詳情功能的實(shí)現(xiàn)
這篇文章主要介紹了Android ViewDragHelper實(shí)現(xiàn)京東、淘寶拖拽詳情,實(shí)現(xiàn)這種效果大概分為三種方式,具體哪三種方式大家通過本文了解下吧2018-04-04淺談Android開發(fā)者2017年最值得關(guān)注的25個(gè)實(shí)用庫
本篇文章主要介紹了Android開發(fā)者2017年最值得關(guān)注的25個(gè)庫,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2017-09-09Android通過SharedPreferences實(shí)現(xiàn)自動(dòng)登錄記住用戶名和密碼功能
最近使用SharedPreferences實(shí)現(xiàn)了一個(gè)android自動(dòng)登錄功能,特此分享到腳本之家平臺(tái)供大家參考2017-07-07Android自定義View實(shí)現(xiàn)圓弧進(jìn)度效果逐步完成過程
在Android開發(fā)中,通過自定義View實(shí)現(xiàn)自己想要的效果是作為android開發(fā)程序員的一項(xiàng)必備技能,自定義View對(duì)于android開發(fā)來說也是比較難的一項(xiàng)技術(shù)2023-04-04Flutter利用Hero組件實(shí)現(xiàn)自定義路徑效果的動(dòng)畫
本篇介紹了如何利用Hero動(dòng)畫組件的createRectTween屬性實(shí)現(xiàn)自定義路徑效果的動(dòng)畫。文中的示例代碼講解詳細(xì),感興趣的可以了解一下2022-06-06如何在Android中實(shí)現(xiàn)漸顯按鈕的左右滑動(dòng)效果
本篇文章是對(duì)在Android中實(shí)現(xiàn)漸顯按鈕的左右滑動(dòng)效果進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06Android Camera實(shí)現(xiàn)毫秒級(jí)拍照實(shí)例
本篇文章主要介紹了Android Camera實(shí)現(xiàn)毫秒級(jí)拍照實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-06-06android 仿微信demo——微信消息界面實(shí)現(xiàn)(服務(wù)端)
本系列文章主要介紹了微信小程序-閱讀小程序?qū)嵗╠emo),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧,希望能給你們提供幫助2021-06-06