Android设置布局背景为白色的三种方法
2013-11-07 00:23
309 查看
一、在xml文件里可以直接设置:
android:background="#ffffff"其他颜色可以看这里;/article/1652168.html
二、在java文件里设置:
LinearLayout myLayout = () findViewById(R.id.linearLayout1);myLayout.setBackgroundColor(Color.WHITE);三、在AndroidManifest.xml里利用android:theme来设置,这个命令还是很强大的,如下所示:theme的设置 可以设置为系统自带的格式,也可以自定义格式。
A: 系统自带格式
@android:style/Theme.Black //背景黑色-有标题-非全屏 @android:style/Theme.Black.NoTitleBar //背景黑色-无标题-非全屏 @android:style/Theme.Black.NoTitleBar.Fullscreen //背景黑色-无标题-全屏显示 @android:style/Theme.Dialog //对话框显示 @android:style/Theme.InputMethod
@android:style/Theme.Light //背景白色-有标题-非全屏 @android:style/Theme.Light.NoTitleBar //背景白色-无标题-非全屏 @android:style/Theme.Light.NoTitleBar.Fullscreen //背景白色-无标题-全屏显示
@android:style/Theme.Light.Panel @android:style/Theme.Light.WallpaperSettings //背景透明 @android:style/Theme.NoDisplay
@android:style/Theme.Translucent.NoTitleBar.Fullscreen //半透明、无标题栏、全屏
@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen
可以在单个Activity里设置,也可以在applicaiton里全局设置。比如:
<activity android:screenOrientation="portrait" android:name=".ui.RegisterActivity" android:theme="@android:style/Theme.NoTitleBar"></activity>
B:也可以自定义
在activity里加入 android:theme="@style/MyTitleBar" 再在 style.xml里加入
<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里,设置背景图。
android:background="#ffffff"其他颜色可以看这里;/article/1652168.html
二、在java文件里设置:
LinearLayout myLayout = () findViewById(R.id.linearLayout1);myLayout.setBackgroundColor(Color.WHITE);三、在AndroidManifest.xml里利用android:theme来设置,这个命令还是很强大的,如下所示:theme的设置 可以设置为系统自带的格式,也可以自定义格式。
A: 系统自带格式
@android:style/Theme.Black //背景黑色-有标题-非全屏 @android:style/Theme.Black.NoTitleBar //背景黑色-无标题-非全屏 @android:style/Theme.Black.NoTitleBar.Fullscreen //背景黑色-无标题-全屏显示 @android:style/Theme.Dialog //对话框显示 @android:style/Theme.InputMethod
@android:style/Theme.Light //背景白色-有标题-非全屏 @android:style/Theme.Light.NoTitleBar //背景白色-无标题-非全屏 @android:style/Theme.Light.NoTitleBar.Fullscreen //背景白色-无标题-全屏显示
@android:style/Theme.Light.Panel @android:style/Theme.Light.WallpaperSettings //背景透明 @android:style/Theme.NoDisplay
@android:style/Theme.Translucent.NoTitleBar.Fullscreen //半透明、无标题栏、全屏
@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen
可以在单个Activity里设置,也可以在applicaiton里全局设置。比如:
<activity android:screenOrientation="portrait" android:name=".ui.RegisterActivity" android:theme="@android:style/Theme.NoTitleBar"></activity>
B:也可以自定义
在activity里加入 android:theme="@style/MyTitleBar" 再在 style.xml里加入
<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里,设置背景图。
相关文章推荐
- Android设置布局背景为白色的三种方法
- Android设置布局背景为白色的三种方法
- Android设置布局背景为白色的三种方法
- Android设置布局背景为白色的三种方法
- Android设置布局背景为白色的三种方法
- Android设置布局背景为白色的三种方法
- Android设置布局背景为白色的三种方法
- Android设置布局背景为白色的三种方法
- (转载)Recyclerview | Intent与Bundle在传值上的区别 | 设置布局背景为白色的三种方法
- Android布局中按钮的设置规则,设置按钮单击事件的三种方法
- Android设置布局背景为颜色、布局样式的方法
- Android 相对布局中的 代码中修改属性与布局文件的设置不同的解决方法
- android在代码中四种设置控件背景颜色的方法(包括RGB)
- 在对话框中设置背景的三种方法
- android中获取布局文件的三种方法
- android设置字体颜色的三种方法
- Android中全屏 取消标题栏,TabHost中设置NoTitleBar的三种方法(强制取消黑边)
- 【Android】设置tabhost位于底部的三种方法
- Android设置网络图片为手机背景图片的方法
- Android中设置文本颜色的三种方法