Ⅰ 如何改变在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和底层驱动的具体实现。