lacas
lacas

Reputation: 14066

Android change widget color at runtime UPDATED

I have a widget, with a framelayout.

Is there a way to change my widgets color/shape in runtime?

I am using a shape xml for the background.

update:

i tried: 1,

            Paint paint=new Paint(); 

            Bitmap bitmap=Bitmap.createBitmap(100, 100, Config.ARGB_8888);
            Canvas canvas=new Canvas(bitmap);
            paint.setColor(Color.RED);
            canvas.drawRoundRect(new RectF(1,1,111,111), 10, 10, paint);

            updateViews.setImageViewBitmap(R.id.FL, bitmap);

--> error loading widget

2,

updateViews.setImageViewResource(R.id.FL, R.drawable.blue);

--> error loading widget

Upvotes: 2

Views: 655

Answers (3)

Giohji
Giohji

Reputation: 773

You can try making a workaround by adding an ImageView to fill the whole FrameLayout and then using the RemoteViews.setImageViewResource(int viewId, int srcId).

Upvotes: 1

fadisdh
fadisdh

Reputation: 602

For Color:

view.setBackgroundColor(Color.parseColor("#FFFFFF"));

For shape or any resourse:

view.setBackgroundResource(R.drawable.my_shape);

Upvotes: 0

espinchi
espinchi

Reputation: 9212

I'll assume your widget is a TextView, and you want to change its color to white.

First you grab a reference to it, by using the ID that you specified in the XML layout:

TextView textView = (TextView) findViewById(R.id.textViewId);

Now, you can just set the color:

textView.setBackgroundColorResource(R.color.white);

Upvotes: 0

Related Questions