View背景颜色设置&Fragment&FragmentDialog
2014-04-19 12:13
225 查看
Android 开发中使用的颜色可以分为两种,自定义颜色和系统颜色:
一>自定义颜色:
颜色值的定义是通过RGB三原色和一个alpha值来定义的(加色原理)。以井号(#)开始,后面是Alpha-Red-Green-Blue的格式,形如:
#RGB
#ARGB
#RRGGBB
#AARRGGBB
通常使用#RRGGBB 或者#AARRGGBB的形式!
one.在资源文件中定义颜色:
一般在 res/values/color/color_name下建立colors.xml文件,定义颜色,如下:
res/values/color/color_name例如:
then. 在布局文件中使用颜色
res/values/color/color_name 例如:
二>系统颜色:
android也有一些内置的颜色,例如系统资源中定义的颜色,十分有限。
android.graphics.Color类中也提供了一些颜色常量和构造颜色值的静态方法。
one.在代码中使用系统颜色:
在这里做一下Fragment的补充,Fragment的使用能大大提升你在做UI方面的功底以及水平。那么,我就给大家一个网址。从这里你能学会Fragment,而且从这里你能重新认识Fragment。在这里包里面有一PDF文档,还有三个为使读者透彻理解Fragment的项目源码。真正的详细介绍了怎么使用Fragment。
好吧,点击这里进入下载页面
在文档中提到了FragmentDialog。所以下面我为大家提供了Fragment的源码。页面不是很美观,这是我为看一下它的效果随便填充了一个布局。效果图:
给你个福利,FragmentDialog对话框源码。点击下载
一>自定义颜色:
颜色值的定义是通过RGB三原色和一个alpha值来定义的(加色原理)。以井号(#)开始,后面是Alpha-Red-Green-Blue的格式,形如:
#RGB
#ARGB
#RRGGBB
#AARRGGBB
通常使用#RRGGBB 或者#AARRGGBB的形式!
one.在资源文件中定义颜色:
一般在 res/values/color/color_name下建立colors.xml文件,定义颜色,如下:
<?xml version="1.0" encoding="utf-8"?> <resourses> <color name="red">#ff0000</color> </resourses>and then. 在代码中使用颜色:
res/values/color/color_name例如:
Button btn = (Button) findViewById(R.id.button); int color = Resources.getSystem().getColor(R.color.red); btn.setBackgroundColor(color); 或者: Button btn = (Button) findViewById(R.id.button); int color=getResources().getColor(R.color.red); btn.setBackgroundColor(color);
then. 在布局文件中使用颜色
res/values/color/color_name 例如:
android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/blue" android:text="Address book" />
二>系统颜色:
android也有一些内置的颜色,例如系统资源中定义的颜色,十分有限。
android.graphics.Color类中也提供了一些颜色常量和构造颜色值的静态方法。
one.在代码中使用系统颜色:
Color类中的颜色常量: Button btn = (Button) findViewById(R.id.button); btn.setBackgroundColor(Color.CYAN); //btn.setBackground(Color.CYAN); 或者使用Color类中的静态常量: Button btn = (Button) findViewById(R.id.button1); btn.setBackgroundColor(Color.argb(0xff, 0xff, 0x00, 0x00)); //btn.setBackground(Color.argb(0xff, 0xff, 0x00, 0x00));
在这里做一下Fragment的补充,Fragment的使用能大大提升你在做UI方面的功底以及水平。那么,我就给大家一个网址。从这里你能学会Fragment,而且从这里你能重新认识Fragment。在这里包里面有一PDF文档,还有三个为使读者透彻理解Fragment的项目源码。真正的详细介绍了怎么使用Fragment。
好吧,点击这里进入下载页面
在文档中提到了FragmentDialog。所以下面我为大家提供了Fragment的源码。页面不是很美观,这是我为看一下它的效果随便填充了一个布局。效果图:
给你个福利,FragmentDialog对话框源码。点击下载
相关文章推荐
- 设置 DialogFragment 的背景颜色透明
- 自定义TextView设置边框与背景颜色添加点击事件,点击更改随机数与背景
- android TextView 设置部分文字背景色和文字颜色
- TextView设置超链接、背景颜色、字体颜色等等,Spannable的使用。
- webview设置背景颜色-android
- 给一个android的TextView设置背景颜色动态显示,到那时好像不起作用。我是少了什么东西么?
- iOS_自定义view里的按钮点击不了+背景颜色也设置不了
- ios 设置UITableView 选中行cell的背景颜色(自定义选中的背景颜色)
- Android通过selector选择器设置Button或者textview的背景颜色,字体颜色
- android的DialogFragment设置全屏之后,里面的View不能充满整个屏幕
- 16进制颜色#e26562与UIColor互转,设置View背景颜色
- 模式对话框Dialog背景的透明度&黑暗度设置方法
- 设置 tableview 的背景颜色,总是不生效
- ios tableview和cell背景颜色设置
- Qt QTableView设置各行的背景颜色
- 模式对话框Dialog背景的透明度&黑暗度设置方法
- TextView设置部分文字背景色和文字颜色
- android--设置TextView部分文字的颜色和背景(高亮显示)
- ios给view设置背景颜色的正确方式
- C++--如何在Dialog和View中显示梯度背景颜色