当前位置:操作系统 > 安卓/Android >>

Android的布景设计(theme)

布景是可以大范围套用的UI美化功能,它的范围为整个屏幕,从程序编码的角度来看,布景可以套用到以下两个范围:

整个应用程序(application)
整个Activity
下面是一个套用整个application布景的例子,自定义一个不显示窗口标题,并改变应用程序的背景颜色。

延续上个工程,编辑style.xml:
[html] <?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="myText"> 
        <item name="android:textSize">18sp</item> 
        <item name="android:textColor">#00FF00</item> 
    </style> 
    <style name="myButton"> 
        <item name="android:background">#00BFFF</item> 
    </style> 
    <style name="myTheme"> 
        <item name="android:windowNoTitle">true</item>  
        <item name="android:background">#087832</item>        
    </style>  
     
</resources> 
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="myText">
        <item name="android:textSize">18sp</item>
        <item name="android:textColor">#00FF00</item>
    </style>
    <style name="myButton">
        <item name="android:background">#00BFFF</item>
    </style>
    <style name="myTheme">
     <item name="android:windowNoTitle">true</item>
     <item name="android:background">#087832</item>      
    </style>
   
</resources>
修改AndroidManifest.XML,在application中加入theme属性:
[html] <?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.android" 
    android:versionCode="1" 
    android:versionName="1.0" > 
 
    <uses-sdk android:minSdkVersion="10" /> 
 
    <application 
        android:theme="@style/myTheme" 
        android:icon="@drawable/ic_launcher" 
        android:label="@string/app_name" > 
        <activity 
            android:name=".YypClickListenerActivity" 
            android:label="@string/app_name" > 
            <intent-filter> 
                <action android:name="android.intent.action.MAIN" /> 
 
                <category android:name="android.intent.category.LAUNCHER" /> 
            </intent-filter> 
        </activity> 
    </application> 
 
</manifest> 
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:theme="@style/myTheme"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".YypClickListenerActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
程序运行效果:

 \





摘自 Young的专栏

补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,