activity theme parent 属性浅析
在AndroidManifest.xml文件中,可以对每一个Activity设置android:theme
theme的设置 可以设置为系统自带的格式,也可以自定义格式。
A: 系统自带格式
1、android:theme="@android:style/Theme"
默认状态,即如果theme这里不填任何属性的时候,默认为Theme
2、android:theme="@android:style/Theme.NoDisplay"
任何都不显示。比较适用于只是运行了activity,但未显示任何东西
3、android:theme="@android:style/Theme.NoTitleBar“
背景主题的没有标题栏的样式,默认如果没有设置的话,显示黑背景
4、android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
背景主题的没有标题栏且全屏的样式,默认为黑背景
5、android:theme="@android:style/Theme.Black"
默认状态下黑背景
6、android:theme="@android:style/Theme.Black.NoTitleBar"
黑背景主题的没有标题栏的样式
7、android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
黑背景主题的没有标题栏且全屏的样式
8、android:theme="@android:style/Theme.Light"
默认状态下亮背景,与上述黑背景Theme.Black相反
9、android:theme="@android:style/Theme.Light.NoTitleBar"
亮背景主题的没有标题栏的样式,与Theme.Black.NoTitleBar相反
10、android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"
亮背景主题的没有标题栏且全屏显示的样式,与Theme.Black.NoTitleBa.Fullscreenr相反
11、android:theme="@android:style/Theme.Dialog"
对话框样式 将整个activity变成对话框样式出现
12、android:theme="@android:style/Theme.InputMethod"
Window animations that are applied to input method overlay windows
13、android:theme="@android:style/Theme.Panel"
删除掉所有多余的窗口装饰,在一个空的矩形框中填充内容,作用范围相当于把dialog中的所有元素全部去掉,只是一个空的矩形框,且此为默认的样式
14、android:theme="@android:style/Theme.Light.Panel"
删除掉所有多余的窗口装饰,在一个空的矩形框中填充内容,作用范围相当于把dialog中的所有元素全部去掉,只是一个空的矩形框,且默认是light的样式
15、android:theme="@android:style/Theme.Wallpaper"
使用墙纸做主题,默认状态。
16、android:theme="@android:style/Theme.WallpaperSettings"
使用墙纸做主题,默认是使用将上一个界面调暗之后作为主题
17、android:theme="@android:style/Theme.Light.WallpaperSettings"
使用墙纸做主题,默认Light状态
18、android:theme="@android:style/Theme.Wallpaper.NoTitleBar"
使用墙纸做主题,且没有标题栏
19、android:theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen"
使用墙纸做主题,且没有标题栏,且全屏显示
20、android:theme="@android:style/Theme.Translucent"
半透明状态下的背景,将运行此activity之前的屏幕作为半透明状态作为此activity运行时的样式。
21、android:theme="@android:style/Theme.Translucent.NoTitleBar"
半透明状态下没有标题栏的背景,将运行此activity之前的屏幕作为半透明状态作为此activity运行时的样式。
22、android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"
半透明状态下没有标题栏且全屏的背景,将运行此activity之前的屏幕作为半透明状态作为此activity运行时的样式
可以在单个Activity里设置,也可以在applicaiton里全局设置。比如:
1 | <activity android:screenOrientation= "portrait" android:name= ".ui.RegisterActivity" android:theme= "@android:style/Theme.NoTitleBar" /> |
B:也可以自定义
在activity里加入 android:theme="@style/MyTitleBar" 再在 style.xml里加入
1 2 3 4 5 6 7 8 9 10 11 12 13 | <style name= "MyTitleBar" parent= "android:Theme" > <item name= "android:windowTitleSize" >50dip</item> <item name= "android:windowTitleBackgroundStyle" > @style /MyTitleBackground</item> <item name= "android:windowTitleStyle" > @style /WindowTitle</item> </style> <!-- 自定义标题栏背景图 --> <style name= "MyTitleBackground" parent= "android:TextAppearance.WindowTitle" > <item name= "android:background" > @drawable /bg_topbar</item> </style> <style name= "WindowTitle" parent= "android:TextAppearance.WindowTitle" > <item name= "android:singleLine" > true </item> </style> |
这里的parent是继承于android:Theme,所以在下面的样式里,只能是window开头的样式才起作用,所有样式请参考\sdk\docs\reference\android\R.attr.html,
也可以设置windowTitleBackgroundStyle 为@style/MyTitleBackground,这样就可以在MyTitleBackground里,设置背景图啦
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库