Ⅰ 如何改變在android中刪除線的顏色
I think this is not possible for simple textview so you have to do the following:-
1.Create a custom TextView by extending View class
2.Declare this custom textview inside XML layout same like we do for TextView.
And at last write an onDraw() method like following.
@Override
protected void onDraw(Canvas canvas) {
Paint paint = new Paint();
paint.setColor(strikeThroughColor);
paint.setStyle(Paint.Style.FILL);
paint.setStrikeThruText(true);
paint.setStrokeWidth(strikeThroughWidth);
paint.setFlags(Paint.ANTI_ALIAS_FLAG);
super.onDraw(canvas);
float width = getWidth();
float heigh = getHeight();
canvas.drawLine(width/10, heigh/10, (width-width/10),(heigh-heigh/10), paint);
}
Ⅱ android 怎麼畫2層圓環
Android繪制兩層圓環,可以使用自定義View,繼承View,重寫裡面的Ondraw方法,花兩個同心圓,示例如下:
java">packagecom.cn.myvn;
importandroid.content.Context;
importandroid.graphics.Canvas;
importandroid.graphics.Paint;
importandroid.util.AttributeSet;
importandroid.view.View;
{
privatefinalPaintpaint;
privatefinalContextcontext;
publicRingView(Contextcontext){
//TODOAuto-generatedconstructorstub
this(context,null);
}
publicRingView(Contextcontext,AttributeSetattrs){
super(context,attrs);
//TODOAuto-generatedconstructorstub
this.context=context;
this.paint=newPaint();
this.paint.setAntiAlias(true);//消除鋸齒
this.paint.setStyle(Paint.Style.STROKE);//繪制空心圓
}
@Override
protectedvoidonDraw(Canvascanvas){
//TODOAuto-generatedmethodstub
intcenter=getWidth()/2;
intinnerCircle=dip2px(context,83);//設置內圓半徑
intringWidth=dip2px(context,5);//設置圓環寬度
//繪制內圓
this.paint.setARGB(155,167,190,206);
this.paint.setStrokeWidth(2);
canvas.drawCircle(center,center,innerCircle,this.paint);
//繪制圓環
this.paint.setARGB(255,212,225,233);
this.paint.setStrokeWidth(ringWidth);
canvas.drawCircle(center,center,innerCircle+1+ringWidth/2,this.paint);
//繪制外圓
this.paint.setARGB(155,167,190,206);
this.paint.setStrokeWidth(2);
canvas.drawCircle(center,center,innerCircle+ringWidth,this.paint);
super.onDraw(canvas);
}
}
Ⅲ android顏色代碼怎麼代入paint.setcolor 0xffff0000
要繪圖,首先得調整畫筆,待畫筆調整好之後,再將圖像繪制到畫布上,這樣才可以顯示在手機屏幕上。Android 中的畫筆是 Paint類,Paint 中包含了很多方法對其屬性進行設置,主要方法如下:
setAntiAlias: 設置畫筆的鋸齒效果。
setColor: 設置畫筆顏色
setARGB: 設置畫筆的a,r,p,g值。
setAlpha: 設置Alpha值
Ⅳ Android 如何實現豎排文字顯示
在android.graphics.Canvas類中有個沿路徑畫字的方法
void drawTextOnPath(String text, Path path, float hOffset, float vOffset, Paint paint)
Draw the text, with origin at (x,y), using the specified paint, along the specified path.
void drawTextOnPath(char[] text, int index, int count, Path path, float hOffset, float vOffset, Paint paint)
Draw the text, with origin at (x,y), using the specified paint, along the specified path.
Test.java代碼://需要在layout中定義Test,且設置背景,在java代碼中設置test Text
public class Test extends View {
private Paint paint;
private Path path;
private Matrix matrix;
private int width = -1;
private int height = -1;
private float left = 3;
private float top = 18;
private String title = "";
BitmapDrawable drawable = (BitmapDrawable) getBackground();
public Test(Context context, AttributeSet attrs) {
super(context, attrs);
paint = new Paint();
paint.setColor(Color.WHITE);//定義字體顏色
paint.setTextSize(14);//定義字體大小
path = new Path();
path.lineTo(0,500);//定義字元路徑
matrix = new Matrix();
Log.v("onMeasure", "2");
}
@Override
protected void onDraw(Canvas canvas) {
//畫背景
Bitmap b = Bitmap.createBitmap(drawable.getBitmap(),0,0,width,height);
canvas.drawBitmap(b, matrix, paint);
//畫字
showText(canvas, title);
}
private void showText(Canvas canvas, String text){
float w;
final int len = text.length();
float py = 0 + top;
for(int i=0; i<len; i ++){
char c = text.charAt(i);
w = paint.measureText(text, i, i+1);//獲取字元寬度
StringBuffer b = new StringBuffer();
b.append(c);
if(py > 81){//定義字的范圍
return;
}
if(isChinese(c)){
py += w;
if(py > 81){
return;
}
canvas.drawText(b.toString(), left, py, paint); //中文處理方法
}else {
canvas.drawTextOnPath(b.toString(), path, py, -left-2, paint);//其他文字處理方法
py += w;
}
}
}
public void setText(String title){
this.title = title;
}
public String getText(){
return title;
}
private boolean isChinese(char c) {
Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
|| ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
|| ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
|| ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
return true;
}
return false;
}
//重寫View大小方法,使view大小為背景圖片大小
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (null != getBackground()) {
int h = drawable.getIntrinsicHeight();
int w = drawable.getIntrinsicWidth();
Log.v("onMeasure", "null != getBackground() h:" + h + " w:" + w);
width = w;
height = h;
setMeasuredDimension(w, h);
} else {
width = widthMeasureSpec;
height = heightMeasureSpec;
super.measure(widthMeasureSpec, heightMeasureSpec);
}
}
}
在Android中,若要通過程序改變屏幕顯示的方向,必須要覆蓋setRequestedOrientation()方法,而若要取得目前的屏幕方向,則需要訪問getRequestedOrientation()方法。本範例為求簡要示範更改做法,設計了一個按鈕,當單擊按鈕的同時,判斷當下的屏幕方向,例如豎排(PORTRAIT),則將其更改為橫排(LANDSCAPE);若為橫排(LANDSCAPE),則將其更改為豎排(PORTRAIT)
Ⅳ android中使用paint怎麼畫虛線
Paint paint = new Paint ( ) ;
paint.setColor ( Color.BLACK ) ;
//設置畫直線格式
paint.setStyle ( Paint.Style.STROKE ) ;
//設置虛線效果
paint.setPathEffect ( new DashPathEffect ( new float [ ] { 3, 2 }, 0 ) ) ;
最後這句是設置虛線效果,里邊的float數組的意思是:先畫長度為3的實線,再間隔長度為2的空白,之後一直重復這個單元。這個數組的長度只要大於等於2就行,你可以設置多個數值,產生不同效果,最後這個0指的是與起始位置的偏移量。
Ⅵ Android 圖形顯示系統(十六) 色彩(顏色)模式解析(一)
在Android Q的系統設置中,新增了色彩模式選項,盡管這項功能其他廠商可能早有應用,但依然值得探討其實現細節。Android Q提供了四種色彩模式:
框架層通過ColorDisplayManager和相關服務來管理色彩模式,定義了四種模式的對應值,如自然色、效果增強、飽和色和自動調節。設置色彩模式的操作通過setColorMode介面進行,主要通過系統設置中的DISPLAY_COLOR_MODE變數變化來觸發相應的處理。
ColorDisplayService在接收到設置變化後,會通過ContentObserver監控DISPLAY_COLOR_MODE,觸發onDisplayColorModeChanged函數,涉及夜光屏和白平衡的設置與色彩模式密切相關。色彩模式會進一步通過DisplayTransformManager的介面傳遞,通過調節飽和度和顯示顏色兩個參數來實現。
飽和度和顯示顏色分別通過mGlobalSaturationFactor和mDisplayColorSetting在SurfaceFlinger中進行控制。SurfaceFlinger會根據飽和因子生成顏色矩陣,並與屏幕顏色處理相關。使用has_wide_color_display屬性判斷屏幕是否支持顏色管理,ColorProfile負責處理屏幕顏色的狀態和功能。
選擇ColorMode時,會根據bestDataSpace、RenderIntent和屏幕支持的特性進行匹配。在添加DisplayDevice時,會初始化ColorModes,根據上下層傳入的參數進行匹配和設置。整個流程涉及了上層設置、框架層管理、以及HAL和底層驅動的具體實現。