如何在android中直接使用spinner为paint.setcolor(Color.Spinnervalue)赋值

时间:2015-07-14 17:12:35

标签: java android eclipse

我有spinner。它包含String列表。我需要直接将该String传递给paint.setcolor(Color.Spinnervalue)。

我的代码是

   String spincolurpos =          spincolour.getItemAtPosition(spincolour.getSelectedItemPosition()).
                    toString();
                        Paint paint = new Paint();
                        paint.setColor(Color.spincolurpos); // Text Color
                        paint.setStrokeWidth(120); // Text Size
                     Canvas canvas = new Canvas(drawableBitmap); 
                        canvas.drawBitmap(drawableBitmap, 0, 0, paint);
                        canvas.drawText(txtdrawtext.toString(), 50, 50, paint);
                        image.setImageBitmap(drawableBitmap);   

我不想让if条件检查微调器值并热编码。我想直接传递。我想可能是一个愚蠢的问题。但我无法得到答案

1 个答案:

答案 0 :(得分:0)

尝试更改

String spincolurpos=spincolour.getItemAtPosition(spincolour.getSelectedItemPosition()).toString();
                    Paint paint = new Paint();
                    paint.setColor(Color.parseColor(spincolurpos));
                    paint.setStrokeWidth(120); // Text Size
                 Canvas canvas = new Canvas(drawableBitmap); 
                    canvas.drawBitmap(drawableBitmap, 0, 0, paint);
                    canvas.drawText(txtdrawtext.toString(), 50, 50, paint);
                    image.setImageBitmap(drawableBitmap);