Android:主题(Theme)

1.主题和样式的区别主要区别在 

  • 主题不能作用于单个View组建,主题应该对整个应用中的所有Activity起作用或者对指定的Activity起作用 

  • 主题定义的格式应该是改变窗口的外观格式,例如窗口变体,窗口边框等 

 

2.自定义主题 

  • 在/res/values/my_style.xml文件增加一个主题,定义主题<style.../>片段如下 

 

<style name="CrazyTheme" parent="@android:style/Theme.Dialog"> 
    <item name="android:windowNoTitle">true</item> 
    <item name="android:windowFullScreen">true</item> 
    <item name="android:windowFrame">@drawable/window_border</item> 
    <item name="android:windowBackground>@drawable/star</item> 
</style> 

可以通过parent属性,继承原有的主题 

 

  • 在定义上面的主题后,接下来在Java代码中使用该主图 

 

public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setTheme(android.R.style.CrazyitTheme); 
    setContentView(R.layout.linear_layout_3); 
} 

还可以在AndroidManifest.xml中对指定应用、指定Activity应用主题,这样更简单 

 

<application android:theme="@style/CrazyitTheme"> 
    ... ... 
</application> 
<activity android:theme="@android:style/Theme.Dialog"> 
</activity>
 

3.Android系统包含了很多系统定义好的theme。总结如下 

主题 

说明 

图例 

Theme.NoTitleBar 

不显示应用程序标题栏 

Image

 

Theme.NoTitleBar.Fullscreen 

不显示应用程序标题栏,并全屏 

Image

 

Theme.Light 

背景为白色 

Image

 

Theme.Light.NoTitleBar 

白色背景并无标题栏 

Image

 

Theme.Light.NoTitleBar.Fullscreen 

白色背景,无标题栏,全屏 

Image

 

Theme.Black 

背景黑色 

Image

 

Theme.Black.NoTitleBar 

黑色背景并无标题栏 

Image

 

Theme.Black.NoTitleBar.Fullscreen 

黑色背景,无标题栏,全屏 

Image

 

Theme.Wallpaper 

用系统桌面为应用程序背景 

Image

 

Theme.Wallpaper.NoTitleBar 

用系统桌面为应用程序背景,且无标题栏 

Image

 

Theme.Wallpaper.NoTitleBar.Fullscreen 

用系统桌面为应用程序背景,无标题栏,全屏 

Image

 

Theme.Translucent 

透明背景 

Image

 

Theme.Translucent.NoTitleBar 

透明背景并无标题 

Image

 

Theme.Translucent.NoTitleBar.Fullscreen 

透明背景并无标题,全屏 

Image

 

Theme.Dialog 

对话框形式显示 

Image

 

Theme.Panel 

面板风格显示 

Image

 

Theme.Light.Panel 

平板风格显示 

Image

 

 


原文地址:https://www.cnblogs.com/dyllove98/p/3161448.html