android的漸變色
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節點配置四周圓角的半徑。