安卓-Activity样式设置(全屏,半透明,标题栏)

先介绍去掉标题栏的方法:

第一种:也一般入门的时候经常使用的一种方法


requestWindowFeature(Window.FEATURE_NO_TITLE); // 去掉标题栏
注意这句一定要写在setContentView()方法的前面,不然会报错的

第二种:在AndroidManifest.xml文件中定义


< application android:icon = " @drawable/icon " android:label = " @string/app_name " android:theme ="@android:style/Theme.NoTitleBar" >

可以看出,这样写的话,整个应用都会去掉标题栏,如果只想去掉某一个Activity的标题栏的话,可以把这个属性加到activity标签里面

第三种:这种在一般的应用中不常用,就是在res/values目录下面新建一个style.xml的文件

例如:


xml version="1.0" encoding="UTF-8" ?> < resources > < style name ="notitle" > < item name ="android:windowNoTitle" > true item > style >   resources >

这样,我们就自定义了一个style,就相当于一个主题,然后在AndroidManifest.xml文件中定义


< application android:icon ="@drawable/icon" android:label ="@string/app_name" android:theme ="@style/notitle" >

这样也可以达到去掉标题栏的效果

三种去掉标题栏方法的总结

第一种,有的时候我们会看到,会先出现标题栏,然后再消失,因为我们只是在activity的oncreate方法中定义的,第二种相对第一种比较好一些,不会出现这种情况,第三种我个人感觉最好,这样把功能分开,便于维护和扩展

再介绍全屏的方法:

第一种


getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

第二种


android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

 

第三种


application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/fullscreem"

 

Android应用开发——系统自带样式Android:theme 

•android:theme="@android:style/Theme.Dialog"   将一个Activity显示为能话框模式
•android:theme="@android:style/Theme.NoTitleBar"  不显示应用程序标题栏
•android:theme="@android:style/Theme.NoTitleBar.Fullscreen"  不显示应用程序标题栏,并全屏
•android:theme="Theme.Light"  背景为白色
•android:theme="Theme.Light.NoTitleBar"  白色背景并无标题栏 
•android:theme="Theme.Light.NoTitleBar.Fullscreen"  白色背景,无标题栏,全屏
•android:theme="Theme.Black"  背景黑色
•android:theme="Theme.Black.NoTitleBar"  黑色背景并无标题栏
•android:theme="Theme.Black.NoTitleBar.Fullscreen"    黑色背景,无标题栏,全屏
•android:theme="Theme.Wallpaper"  用系统桌面为应用程序背景
•android:theme="Theme.Wallpaper.NoTitleBar"  用系统桌面为应用程序背景,且无标题栏
•android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen"  用系统桌面为应用程序背景,无标题栏,全屏
•android:theme="Translucent" 
•android:theme="Theme.Translucent.NoTitleBar" 
•android:theme="Theme.Translucent.NoTitleBar.Fullscreen" 
•android:theme="Theme.Panel" 
•android:theme="Theme.Light.Panel"

 

你可能感兴趣的:(安卓)