I write a desktop widget consisting of one TextView with text (API 16+). I create shape.xml to round the corners of the TextView. On the screen, everything turns out beautifully. Next in the widget settings you need to change the background color. I do remoteViews.setInt (R.id.layout, "setBackgroundColor", color). The color changes, but the widget becomes rectangular, without rounding the corners. Why is this happening? Where does the given form go?

How, then, to change the color of the widget, if it is hard-coded in the xml shape?

  • This is due to the fact that you first assign your custom shape to the background, and then you substitute the background for just a color - it becomes the background of your widget instead of the shape, and the widget view is used as standard. - pavlofff
  • THX. That is, it is impossible to change color dynamically if the shape is saved? Or somehow you can? The option to create several shapes with different colors is not particularly suitable. - Jazon
  • It is necessary to change the color of the shape itself, but I worked with widgets a little and I can’t give you anything concrete. In general, there are Tint or other options for this, but this is for widgets on the markup. - pavlofff
  • So the shape color is registered in xml. How to change it programmatically? - Jazon
  • xml is just an object description form. You can create an object through xml and then access it programmatically (after an inflate, the xml description of the object turns into a full-fledged object that can be accessed from the code), changing any properties only with widgets on the screen is more difficult, since direct access There are no objects - pavlofff

0