<bdo id='i2MfS'></bdo><ul id='i2MfS'></ul>
    1. <tfoot id='i2MfS'></tfoot>

      <small id='i2MfS'></small><noframes id='i2MfS'>

      1. <i id='i2MfS'><tr id='i2MfS'><dt id='i2MfS'><q id='i2MfS'><span id='i2MfS'><b id='i2MfS'><form id='i2MfS'><ins id='i2MfS'></ins><ul id='i2MfS'></ul><sub id='i2MfS'></sub></form><legend id='i2MfS'></legend><bdo id='i2MfS'><pre id='i2MfS'><center id='i2MfS'></center></pre></bdo></b><th id='i2MfS'></th></span></q></dt></tr></i><div id='i2MfS'><tfoot id='i2MfS'></tfoot><dl id='i2MfS'><fieldset id='i2MfS'></fieldset></dl></div>
        <legend id='i2MfS'><style id='i2MfS'><dir id='i2MfS'><q id='i2MfS'></q></dir></style></legend>

        在小部件中动态设置 ImageView 的圆角?

        时间:2023-09-08

          • <bdo id='IXJsz'></bdo><ul id='IXJsz'></ul>
              <tbody id='IXJsz'></tbody>

              <legend id='IXJsz'><style id='IXJsz'><dir id='IXJsz'><q id='IXJsz'></q></dir></style></legend>
                <tfoot id='IXJsz'></tfoot>

                <small id='IXJsz'></small><noframes id='IXJsz'>

                <i id='IXJsz'><tr id='IXJsz'><dt id='IXJsz'><q id='IXJsz'><span id='IXJsz'><b id='IXJsz'><form id='IXJsz'><ins id='IXJsz'></ins><ul id='IXJsz'></ul><sub id='IXJsz'></sub></form><legend id='IXJsz'></legend><bdo id='IXJsz'><pre id='IXJsz'><center id='IXJsz'></center></pre></bdo></b><th id='IXJsz'></th></span></q></dt></tr></i><div id='IXJsz'><tfoot id='IXJsz'></tfoot><dl id='IXJsz'><fieldset id='IXJsz'></fieldset></dl></div>
                  本文介绍了在小部件中动态设置 ImageView 的圆角?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个带有配置活动的小部件,用户可以在其中从颜色选择器中选择小部件背景的颜色.我正在使用下面的方法,其中我有一个 ImageView 并创建了一个我在 ImageView 上动态设置的位图.

                  I have a widget with a config activity, where the user can select a color for the background of the widget from a color picker. I am using the method below where I have an ImageView and create a Bitmap which I dynamically set on the ImageView.

                  http://konsentia.com/2011/03/dynamically-changed-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));
                  

                  我想要做的是让用户也可以选择他们是否想要小部件上的圆角.是否可以动态更改颜色以及小部件是否具有圆角?从我看过的圆角示例中,您似乎需要知道视图的尺寸,以便在设置位图之前可以圆角边缘.我认为这在小部件中是不可能的……有什么想法吗?

                  What I want to do though is let the user also choose if they want rounded corners on the widget. Is it possible to dynamically change both the color and whether the widget has rounded corners? From the examples I have looked at for rounding corners it seems you need to know the dimensions of the View so that you can round the edges before setting the Bitmap. I don't think this is possible from within a widget though... any ideas?

                  推荐答案

                  有两种方法:

                  1. 创建一个圆角/方角的位图(使用您现有的方法),该位图的大小与您想要的小部件的大小大致相同.如果用户调整小部件的大小或在具有您未考虑到的某些屏幕分辨率/DPI 的设备上使用它,则存在位图扭曲的风险
                  2. 创建一些带圆角的白色9 补丁位图资源角和方角并使用 RemoteViews.setInt 更改小部件背景 ImageView 的颜色/透明度(需要 Froyo 或更高版本),例如

                  1. Create a bitmap with rounded/square corners (using your existing method) that is roughly the size of the widget you want. This has risk of the bitmap distorting if the user resizes the widget or uses it on a device with some screen resolution/DPI you have not taken into consideration
                  2. Create some white 9 patch bitmap resources with rounded corners and square corners and use RemoteViews.setInt to change the color/transparency of the widget background ImageView (requires Froyo or greater), e.g.

                  if(roundCorners)
                      remoteViews.setImageViewResource(R.id.widget_background, R.drawable.round_corners);
                  else
                      remoteViews.setImageViewResource(R.id.widget_background, R.drawable.square_corners);  
                  
                  remoteViews.setInt(R.id.widget_background, "setColorFilter", someColor);
                  remoteViews.setInt(R.id.widget_background, "setAlpha", someAlphaLevel);
                  

                  我已经使用了这两种方法并推荐 (2) 以获得最大的兼容性.

                  I've used both methods and recommend (2) for maximum compatibility.

                  这篇关于在小部件中动态设置 ImageView 的圆角?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:FCM 令牌何时到期? 下一篇:Android:如何创建自定义按钮小部件

                  相关文章

                • <tfoot id='y9vm1'></tfoot>
                • <i id='y9vm1'><tr id='y9vm1'><dt id='y9vm1'><q id='y9vm1'><span id='y9vm1'><b id='y9vm1'><form id='y9vm1'><ins id='y9vm1'></ins><ul id='y9vm1'></ul><sub id='y9vm1'></sub></form><legend id='y9vm1'></legend><bdo id='y9vm1'><pre id='y9vm1'><center id='y9vm1'></center></pre></bdo></b><th id='y9vm1'></th></span></q></dt></tr></i><div id='y9vm1'><tfoot id='y9vm1'></tfoot><dl id='y9vm1'><fieldset id='y9vm1'></fieldset></dl></div>
                      <bdo id='y9vm1'></bdo><ul id='y9vm1'></ul>

                    <small id='y9vm1'></small><noframes id='y9vm1'>

                  1. <legend id='y9vm1'><style id='y9vm1'><dir id='y9vm1'><q id='y9vm1'></q></dir></style></legend>