如何使一个可绘制对象,在code我选择的颜色对象、颜色、code

2023-09-04 05:23:11 作者:蹲街式↗想念

我试图设置选定颜色的图标为preference:

  preference PRF =(preference)找到preference(SelectColor preF)​​;
 

prf.setIcon(Drawbale图标);

有关这方面,我需要选择颜色的物体绘制对象

这是可能使在Java中code进行绘制对象图标?请指导我..

问候,

/////////////////////////////////////////////// ////////////

3D max旋转 为什么我对选中的多个对象旋转90度,结果是单个对象各自旋转90度,之前做的时候还可以

在以下阿莱克斯G的概念,它解决的是:

  preference TextClr preF =(preference)找到preference(text_color_ preference);

位图BM = Bitmap.createBitmap(30,30,Bitmap.Config.ARGB_8888);
帆布CNV =新的Canvas(BM);
INT红色= 0xFFFF0000地址;
cnv.drawColor(红色);
可绘制绘制=新BitmapDrawable(BM);

TextClr preF .setIcon(绘制);
 

解决方案

您应该可以使用code与此类似,以建立一个坚实的颜色绘制对象:

 位图BM = BitmapFactory.createBitmap(50,50,Bitmap.Config.ARGB_8888);
帆布CNV =新的Canvas(BM);
INT红色=为0xFF0000;
cnv.drawColor(红色);
可绘制绘制=新BitmapDrawable(BM);
 

这将创建一个包含一个50×50像素的红色正方形的可绘制。

(请注意,我没有测试此code,但我用我的code类似的东西。)

I am trying to set icon of selected color to a preference:

Preference prf = (Preference) findPreference("SelectColorPref");

prf.setIcon(Drawbale icon);

For this i need an object Drawable of selected color.

Is this possible to make a Drawable icon in java code? Please guide me..

Regards,

///////////////////////////////////////////////////////////

After following Aleks G's concept it solved as:

Preference TextClrPref = (Preference) findPreference("text_color_preference");

Bitmap bm = Bitmap.createBitmap(30, 30, Bitmap.Config.ARGB_8888); 
Canvas cnv = new Canvas(bm); 
int red = 0xffff0000; 
cnv.drawColor(red); 
Drawable drawable = new BitmapDrawable(bm); 

TextClrPref .setIcon(drawable);

解决方案

You should be able to create a solid-colour Drawable using code similar to this:

Bitmap bm = BitmapFactory.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
Canvas cnv = new Canvas(bm);
int red = 0xff0000;
cnv.drawColor(red);
Drawable drawable = new BitmapDrawable(bm);

This will create a Drawable containing a 50x50 pixels red square.

(Please note that I haven't tested this code, but I use something similar in my code.)