Android之怎么自定义样式和主题
Android之如何自定义样式和主题
样式:对某个组件起作用
主题:对整个应用程序或某个Activity起作用
样式:
例:
在values/style.xml中定义
普通定义:
<style name="mystyle">
<item name="android:textColor">@color/mycolor1</item>
<item name="android:textSize">24sp</item>
</style>
继承定义:(类似于Java继承机制,子样式拥有父样式中的的所有定义,
即:使用子样式会把父样式也用上,
而使用父样式只会使用父样式的定义跟子样式没关系)
<style name="mystyle1">
<item name="android:textColor">@color/mycolor2</item>
</style>
<style name="substyle" parent="mystyle1">
<item name="android:textSize">35sp</item>
</style>
自定义主题:
(也支持继承)
在values/style.xml中定义
<style name="mytheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
<style name="mytheme1">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">?android:windowFullscreen</item>
</style>
?android:windowFullscreen 表示以获取的返回值作为设置参数
例:对整个应用程序设置:
在AndroidManifest.xml里面配置
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >//设置整个应用程序的主题
......省略
对某个应用程序的某个Activity(一屏)设置主题:
在AndroidManifest.xml里面配置
.....略
<activity
android:name="com.example.androidui.MainActivity"
android:label="@string/app_name"
android:theme="@style/mythem"//对某个Activity设置主题
>
.....略
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
黑屏,无标题,全屏
@android:style/Theme.Dialog 弹出小窗体形式
@android:style/Theme.Wallpaper 使用桌面墙纸
@android:style/Theme.Translucent 半透明效果
@android:style/Theme.Panel 面板样式尽可能小的在中央显示
样式:对某个组件起作用
主题:对整个应用程序或某个Activity起作用
样式:
例:
在values/style.xml中定义
普通定义:
<style name="mystyle">
<item name="android:textColor">@color/mycolor1</item>
<item name="android:textSize">24sp</item>
</style>
继承定义:(类似于Java继承机制,子样式拥有父样式中的的所有定义,
即:使用子样式会把父样式也用上,
而使用父样式只会使用父样式的定义跟子样式没关系)
<style name="mystyle1">
<item name="android:textColor">@color/mycolor2</item>
</style>
<style name="substyle" parent="mystyle1">
<item name="android:textSize">35sp</item>
</style>
自定义主题:
(也支持继承)
在values/style.xml中定义
<style name="mytheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
<style name="mytheme1">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">?android:windowFullscreen</item>
</style>
?android:windowFullscreen 表示以获取的返回值作为设置参数
例:对整个应用程序设置:
在AndroidManifest.xml里面配置
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >//设置整个应用程序的主题
......省略
对某个应用程序的某个Activity(一屏)设置主题:
在AndroidManifest.xml里面配置
.....略
<activity
android:name="com.example.androidui.MainActivity"
android:label="@string/app_name"
android:theme="@style/mythem"//对某个Activity设置主题
>
.....略
3使用系统定义好的主题:
在AndroidManifest.xml里面配置
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
黑屏,无标题,全屏
@android:style/Theme.Dialog 弹出小窗体形式
@android:style/Theme.Wallpaper 使用桌面墙纸
@android:style/Theme.Translucent 半透明效果
@android:style/Theme.Panel 面板样式尽可能小的在中央显示
版权声明:本文为博主原创文章,未经博主允许不得转载。