当前位置:首页 » 安卓系统 » android的渐变色

android的渐变色

发布时间: 2022-11-22 18:03:20

A. android 动态设置按钮背景的渐变颜色

在一个xml文件中定义需要用到gradient,然后用drawable设置,大致是这样

B. android 怎么自定义颜色渐变

1.在res/drawable/里新建XML文件(background_color.xml)
内容:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#000000"
android:endColor="#FFFFFF"
android:angle="90"
/>

</shape>
备:angle(角度)的值只可为:45 90 135 180等45的倍数

2.在res/layout里使用时:
颜色设置段:Android:src="@drawable/background_color

C. 长按如何使进度条变化Android

通过MediaPlayer调节。
系统自带的进度条的颜色比较单调,实际开发中使用较少,可以自定义进度条背景,新建一个progressbarbg.xml文件。gradient可以设置进度条的渐变色,android:endColor和android:startColor可以设置渐变开始和结束的颜色。定义完成以后,便可以使用。
在音乐进度,网络下载时,需动态加载进度条,默认情况下,设置进度条,使用setProgress即可。但有时除了动态设置进度,仍需要动态设置进度条颜色通过MediaPlayer播放音乐并获取进度,设置进度。

D. android怎么用paint实现图像的渐变出现

在android.graphics中提供了有关Gradient字样的类,例如LinearGradient线性渐变、RadialGradient径向渐变和SweepGradient角度渐变三种,他们的基类为android.graphics.Shader。为了演示图像渐变效果,下面给出一个简单的实例。一、LinearGradient线性渐变在android平台中提供了两种重载方式来实例化该类分别为,他们的不同之处为参数中第一种方法可以用颜色数组,和位置来实现更细腻的过渡效果,比如颜色采样int[]colors数组中存放20种颜色,则渐变将会逐一处理。而第二种方法参数仅为起初颜色color0和最终颜色color1。LinearGradient(floatx0,floaty0,floatx1,floaty1,int[]colors,float[]positions,Shader.TileModetile)LinearGradient(floatx0,floaty0,floatx1,floaty1,intcolor0,intcolor1,Shader.TileModetile)使用实例如下:Paintp=newPaint();LinearGradientlg=newLinearGradient(0,0,100,100,Color.RED,Color.BLUE,Shader.TileMode.MIRROR);//参数一为渐变起初点坐标x位置,参数二为y轴位置,参数三和四分辨对应渐变终点,最后参数为平铺方式,这里设置为镜像刚才已经讲到Gradient是基于Shader类,所以我们通过Paint的setShader方法来设置这个渐变,代码如下:p.setShader(lg);canvas.drawCicle(0,0,200,p);//参数3为画圆的半径,类型为float型。二、RadialGradient镜像渐变有了上面的基础,我们一起来了解下径向渐变。和上面参数唯一不同的是,径向渐变第三个参数是半径,其他的和线性渐变相同。RadialGradient(floatx,floaty,floatradius,int[]colors,float[]positions,Shader.TileModetile)RadialGradient(floatx,floaty,floatradius,intcolor0,intcolor1,Shader.TileModetile)三、SweepGradient角度渐变对于一些3D立体效果的渐变可以尝试用角度渐变来完成一个圆锥形,相对来说比上面更简单,前两个参数为中心点,然后通过载入的颜色来平均的渐变渲染。SweepGradient(floatcx,floatcy,int[]colors,float[]positions)//对于最后一个参数SDK上的描述为MaybeNULL.,beginningwith0andendingwith1.0.Ifthevaluesarenotmonotonic,.IfpositionsisNULL,.,所以建议使用下面的重载方法,本方法一般为NULL即可。SweepGradient(floatcx,floatcy,intcolor0,intcolor1)到此,希望大家对图像特效处理有了一定的认识,了解这些对打好Android游戏开发的基础很有好处。转载

E. android怎么用paint实现图像的渐变出现

其他的和线性渐变相同。为了演 示图像渐变效果。

一, float radius, float x1。

SweepGradient(float cx。

LinearGradient(float x0,所以建议使用下面的重载方法,他们的基类为android、RadialGradient镜像渐变
有了上面的基础. If positions is NULL,代码如下,他们的不同之处为参数中第一种方法可以用颜色数组, int color1, float radius;/,然后通过载入的颜色来平均的渐变渲染, the drawing may proce unexpected results, int[] colors.RED,p).TileMode tile)

使用实例如下.TileMode, float[] positions; /, int color0,最后参数为平铺方式, Shader,100, float y0. If the values are not monotonic.graphics, float y1,这里设置为镜像
刚才已经讲到Gradient是基于Shader类,前两个参数为中心点.TileMode tile)

LinearGradient(float x0.drawCicle(0;
canvas.Shader,参数三和四分辨对应渐变终点.TileMode tile)

三, int color0,所以我们通过Paint的setShader方法来设置这个渐变,200,则渐变将会逐一处理。
二, float[] positions,径向渐变第三个参数是半径, int[] colors在android, beginning with 0 and ending with 1,本方法一般为NULL即可.、SweepGradient角度渐变
对于一些3D立体效果的渐变可以尝试用角度渐变来完成一个圆锥形, float cy. The relative position of each corresponding color in the colors array.setShader(lg),和位置来实现更细腻的过渡效果, 比如颜 色采样int[] colors数组中存放20种颜色, float x1,Shader。

RadialGradient(float x, float[] positions) /。而第二种方法参数仅为起初颜色color0和最终颜色color1, Shader。和上面参数唯一不同的是, then the colors are automatically spaced evenly,0, float y,了解这些对打好Android游戏开发的基础很有好处;对于最后一个参数SDK上的描述为May be NULL.graphics中提供了有关Gradient字样的类, Shader。

SweepGradient(float cx;参数3为画圆的半径;
LinearGradient lg=new LinearGradient(0,希望大家对图像特效处理有了一定的认识,0,参数二为y轴位置,我们一起来了解下径向渐变;/,类型为float型,相对来说比上面更简单,Color; /, int color1)

到此,100,Color.TileMode tile)

RadialGradient(float x.MIRROR).BLUE, float y0, int color0,例如LinearGradient线性渐变:

p, int color1、LinearGradient线性渐变
在android平台中提供了两种重载方式来实例化该类分别为,下面给出一个简单的实例, int[] colors, float cy, Shader, float y1;参数一为渐变起初点坐标x位置:

Paint p=new Paint(), float y.0、 RadialGradient径向渐变和SweepGradient角度渐变三种。

F. Android studio中怎么将方形按钮设置成圆角以及渐变效果

一、在 studio中res 包下的drawable中建立一个shape的文件,系统会给你一个默认的方形然后你就可以开始设置你需要的效果。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:Android="http://schemas.android.com/apk/res/android">

<!--填充背景色 -->
<solid android:color="#ffff00" /> //solid 指的是背景颜色的设置

<!--描边 他需要 2个参数,颜色 第二参数 宽度 -->
<stroke
android:width="2dp" //width 指的是边框的宽度
android:color="#ff00ff" /> //color指的是边框的颜色

<!-- 设置弧度 Radius设置所有角的弧度 --> //radius 指的就是角的弧度
<corners //方形存在四个角,我们可以同时设置四个角,也可以分开设置
android:bottomLeftRadius="20dp" //左下角
android:bottomRightRadius="20dp" //右下角
android:topLeftRadius="20dp" //左上角
android:topRightRadius="20dp" /> //右上角

//同时设置:<corners
android:Radius="20dp" /> //四个角同时设置

<!-- 渐变色 startColor 启示颜色 endColor最终颜色 type类型(如果类型为radial(径向渐变,一个圆心以半径的方式渐变),必须加上 android:gradientRadius="**")-->
<gradient
android:startColor="#ff0000" //开始颜色
android:endColor="#ffffff" //结束颜色
android:type="linear" /> //水平渐变 从左到右 type 指的是渐变的模式

<!--内容与边框的间距-->
<padding
android:bottom="15dp"
android:left="15dp"
android:right="15dp"
android:top="15dp" />

<!--如果设置了渐变色 那么背景颜色将不显示 -->

</shape>
<gradient>
shape的颜色渐变属性
attributes:

android:angle
Integer,代表渐变颜色的角度, 0 is left to right, 90 is bottom to top. 必须是45的整数倍.
默认是 0.该属性只有在type=linear情况下起作用,默认的type为linear。
默认情况下,从左到右:

xml代码:<gradient
android:startColor="#000000"
android:endColor="#ffffff"
/>

angle=270,从上到下 :

xml代码:<gradient
android:startColor="#000000"
android:endColor="#ffffff"
android:angle="270"
/>
android:startColor
Color. 颜色渐变的开始颜色,如angle=270中的 android:startColor="#000000"
android:endColor
Color. 颜色渐变的结束颜色,如angle=270中的 android:endColor="#ffffff"
android:centerColor
Color. 颜色渐变的中间颜色,主要用于多彩。

<gradient
android:startColor="#000000"
android:endColor="#ffffff"
android:centerColor="#ff0000"
/>
android:centerX
Float.(0 - 1.0) 相对X的渐变位置。
android:centerY
Float.(0 - 1.0) 相对Y的渐变位置。
这两个属性只有在type不为linear情况下起作用。
android:gradientRadius
Float. 渐变颜色的半径,单位应该是像素点. 需要 android:type="radial".
如果android:type="radial",没有设置android:gradientRadius,将会报错,error inflating class.

xml代码:
<gradient
android:startColor="#ff0000"
android:endColor="#ffffff"
android:centerX="0.5"
android:centerY="0.5"
android:gradientRadius="30"
android:type="radial"
/>
加入Android:centerColor属性

<gradient
android:startColor="#ff0000"
android:endColor="#ffffff"
android:centerColor="#000000"
android:centerX="0.5"
android:centerY="0.5"
android:gradientRadius="30"
android:type="radial"
/>
android:type
Value Description
"linear" 线性渐变.可以理解为 y=kx+b.
"radial" A radial gradient.圆形渐变,起始颜色从cenralX,centralY点开始。
"sweep" A sweeping line gradient.

centerX="0.2" centerX="0.2"

xml代码:
<gradient
android:startColor="#ff0000"
android:endColor="#ffffff"
android:centerX="0.2"
android:centerX="0.2"
android:gradientRadius="30"
android:type="radial"
/>
type="sweep":

xml代码:
<gradient
android:startColor="#ff0000"
android:endColor="#ffffff"
android:centerX="0.5"
android:centerY="0.5"
android:type="sweep"
/>

G. android 怎样设置自定义线颜色渐变效果

1.在res/drawable/里新建XML文件(background_color.xml)
内容:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="">
<gradient
android:startColor="#000000"
android:endColor="#FFFFFF"
android:angle="90"
/>

</shape>
备:angle(角度)的值只可为:45 90 135 180等45的倍数

2.在res/layout里使用时:
颜色设置段:Android:src="@drawable/background_color

H. android 从一个颜色渐变到另外一个颜色

画图的话

java">LinearGradientlg=newLinearGradient(statrX,statrY,statrX,
stopY,newint[]{Color.rgb(5,254,4),
Color.rgb(189,254,0),Color.rgb(255,142,4),
Color.rgb(248,0,1),Color.rgb(148,0,78),
Color.rgb(121,2,43)},newfloat[]{0,0.2f,0.4f,
0.6f,0.8f,1.0f},TileMode.MIRROR);
//这个是y轴上的变化从绿色到橘黄色到大红色到黑红色。。。
//float数组相当于把Y轴平分为5段
paint.setShader(lg);
线程的话
Handlerhandler=newHandler(){
publicvoidhandleMessage(android.os.Messagemsg){
switch(msg.what){
case100:
textView.setTextColor(colors[msg.arg1]);//颜色的数组,和下面的for的次数要等
break;

default:
break;
}
};
};
privatevoidhuatu(){
//TODOAuto-generatedmethodstub
newThread(newRunnable(){

@Override
publicvoidrun(){
//TODOAuto-generatedmethodstub

try{
for(inti=0;i<5;i++){
Thread.sleep(200);
Messagemessage=newMessage();
message.what=100;
message.arg1=i;
handler.sendMessage(message);
}

}catch(InterruptedExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}

}
}).start();
}

I. Android TextView 渐变色

简单的实现方式:

/**

* 设置TextView 的颜色渐变

*/

public void setTextViewStyles(TextView text) {

            // LinearGradient  前四个参修改可以有不同的方向哦

            LinearGradient mLinearGradient =new LinearGradient(0, 0, 0,

            text.getPaint().getTextSize(), Color.parseColor("#FFD800"),

            Color.parseColor("#FFC107"), Shader.TileMode.CLAMP);

            text.getPaint().setShader(mLinearGradient);

            text.invalidate();

}

写在最后: 方式有很多种, 我就不一一列举啦~  谢谢 

J. android怎么设置字体渐变色 不是背景渐变

●使用XML的方式为背景添加渐变效果
1、在res/drawable文件夹里添加一个jbshape.xml文件,然后写入如下代码:
<?xml version="1.0" encoding="utf-8"?>

<gradient
android:angle="270"
android:centerColor="#00FFFF"
android:centerX="0.5"
android:centerY="0.5"
android:endColor="#666666"
android:startColor="#0099FF" />

<padding
android:bottom="7dp"
android:left="7dp"
android:right="7dp"
android:top="7dp" />

<corners android:radius="4dp" />

</shape>
说明:
(1)shape节点配置的是图形的形式,主要包括方形、圆形等,上边代码为方形。
(2)gradient节点主要配置起点颜色、终点颜色及中间点的颜色、坐标、渐变效果(0,90,180从左到右渐变,270从上到下渐变)默认从左到右。
(3)corners节点配置四周圆角的半径。

热点内容
迷人的保姆ftp 发布:2024-05-10 02:05:06 浏览:644
安卓滴滴如何删除行程订单 发布:2024-05-10 01:57:30 浏览:59
桌面默认存储路径怎么改 发布:2024-05-10 01:37:56 浏览:125
数控机器人编程 发布:2024-05-10 01:37:17 浏览:519
长江存储研发 发布:2024-05-10 01:29:19 浏览:686
安卓植物大战僵尸2怎么id登录 发布:2024-05-10 01:17:04 浏览:249
荣耀v8铃声文件夹 发布:2024-05-10 01:11:35 浏览:369
php快速入门及项目实战 发布:2024-05-10 01:00:25 浏览:399
道德编程 发布:2024-05-10 00:31:48 浏览:195
监控配置关联存储服务器 发布:2024-05-09 23:50:34 浏览:271