Android-代码实现view的背景渐变色
来源:互联网 发布:redis查询数据库数量 编辑:程序博客网 时间:2024/06/17 14:39
设置view的背景颜色,有两种方法,一种是通过代码写的形式,一种是通过写一个xml的形式
先说第一种,用代码实现view的背景渐变色:
int colors[] = { 0xff2D0081 , 0xff8B3097, 0xffD14E7A }; GradientDrawable bg = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors);int sdk = android.os.Build.VERSION.SDK_INT;if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) { mainView.setBackgroundDrawable(bg);} else { mainView.setBackground(bg);}
第二种,通过xml的方式:
在res/drawable里定义一个xml,为background_color.xml 例如
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="#2D0081" android:angle="-90" android:centerY="50%" android:centerColor="#8B3097" android:centerX="50%" android:endColor="#D14E7A"/></shape>
这里完成了一个xml,然后在界面布局里面通过backgroundcolor的形式使用 res/layout/main_view.xml中 例如:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/background_color"> </LinearLayout>
0 0
- Android-代码实现view的背景渐变色
- 渐变色的背景实现
- iOS之view的背景绘制渐变色、文字渐变
- Android背景渐变色(shape,gradient)的实现,gradient
- android背景渐变色
- Android:背景渐变色
- Android背景渐变色
- Android 渐变色背景
- iOS实现背景的渐变色
- Android-实现背景渐变动画
- 纯CSS实现的背景渐变效果代码!
- 设置view渐变背景的工具方法
- View的背景颜色渐变变化
- 表格背景渐变的实现
- div渐变背景的实现
- android代码实现渐变
- View设置背景渐变色(shape,gradient)
- View 渐变背景
- linux0.11 execve系统调用分析
- Android-高级UI控件_ProgressBar进度条
- Android 判断SD卡是否存在及容量
- cocos2dx.2.0升级到3.0 一些常见变化
- typedef与一维数组
- Android-代码实现view的背景渐变色
- GitCafe正式入驻SegmentFault开设专栏
- GitCafe诚邀您一起参加“上海交通大学黑客马拉松”
- GitCafe邀您参加11月22-23日的清华THacks黑客马拉松
- linux内核驱动-内核初涉
- 排序技术_各种算法原理 图解 代码实现
- Android笔记----深入理解Activity
- 移动互联网大讨论(三):肉搏的时代
- avi文件格式详解(一)