style可以用来描述一个View或Window的外观,而Theme用来描述Activity和Application的外观。
【效果图】【代码要点】 style.xml<?xml version="1.0" encoding="utf-8"?> <resources> <mce:style name="NewTheme" parent="android:Theme.Black"><!-- <item name="android:windowNoTitle">true</item> <item name="android:textSize">14sp</item> <item name="android:textColor">#FFFF0000</item> --></mce:style><style name="NewTheme" parent="android:Theme.Black" mce_bogus="1"> <item name="android:windowNoTitle">true</item> <item name="android:textSize">14sp</item> <item name="android:textColor">#FFFF0000</item> </style> </resources>
AndroidManifest.xml:用style来修饰application
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="enleo.StyleTest" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="7" /> <application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/NewTheme"> <activity android:name=".StyleTest" 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>
【效果图】窗口主题
【代码要点】 AndroidManifest.xml:用style来修饰activity <application android:icon="@drawable/icon" android:label="@string/app_name" > <activity android:name=".StyleTest" android:theme="@android:style/Theme.Dialog" 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>
【效果图】透明主题
【代码要点】 AndroidManifest.xml:用style来修饰activity <activity android:name=".StyleTest" android:theme="@android:style/Theme.Translucent" android:label="@string/app_name">
【效果图】窗口主题+自定义背景图
【代码要点】styles.xml<mce:style name="CustomDialogTheme" parent="@android:style/Theme.Dialog"><!-- <item name="android:windowBackground">@drawable/background</item> --></mce:style><style name="CustomDialogTheme" parent="@android:style/Theme.Dialog" mce_bogus="1"> <item name="android:windowBackground">@drawable/background</item></style>