我有一个小部件,其中包含一个配置活动。在这个活动中,用户可以从颜色选择器中选择小部件背景的颜色。我使用下面的方法:我有一个 ImageView,并创建了一个位图,我将其动态地设置在 ImageView 上。
参考链接:http://konsentia.com/2011/03/dynamically-changing-the-background-color-in-android-widgets/
参考链接:http://konsentia.com/2011/03/dynamically-changing-the-background-color-in-android-widgets/
public static Bitmap getBackground (int bgcolor)
{
try
{
Bitmap.Config config = Bitmap.Config.ARGB_8888; // Bitmap.Config.ARGB_8888 Bitmap.Config.ARGB_4444 to be used as these two config constant supports transparency
Bitmap bitmap = Bitmap.createBitmap(2, 2, config); // Create a Bitmap
Canvas canvas = new Canvas(bitmap); // Load the Bitmap to the Canvas
canvas.drawColor(bgcolor); //Set the color
return bitmap;
}
catch (Exception e)
{
return null;
}
}
那么
remoteViews.setImageViewBitmap(R.id.bgcolor, getBackground(bgcolor));
然而,我希望用户也能选择小部件是否要有圆角。是否可以动态更改小部件的颜色和是否有圆角?从我查看的圆角示例中,似乎需要知道视图的尺寸才能在设置位图之前对边缘进行处理。但我不认为这在小部件内是可能的...有什么想法吗?