Android - new BitmapDrawable deprecated 创建一个空白的drawable
2014-12-08 11:22
183 查看
创建一个空白的drawable
myPopupWindow.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
I've used a PopupWindow. With this PopupWindow I set the BackgroundDrawable to an empty BitmapDrawable.
When I use the following code it gives a deprecated warning:
So I changed it to:
This gave me an error that a Bitmap must have a width and height bigger than 0.
Right now I use:
And it works. But it just seems a bit wrong to use a 1x1 pixel Bitmap instead of a completely empty one like I want to. Is there another way to actually use an empty BitmapDrawable, instead of one that is 1 by 1 pixels?
myPopupWindow.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
I've used a PopupWindow. With this PopupWindow I set the BackgroundDrawable to an empty BitmapDrawable.
When I use the following code it gives a deprecated warning:
[code]myPopupWindow.setBackgroundDrawable(new BitmapDrawable());
So I changed it to:
[code]myPopupWindow.setBackgroundDrawable(new BitmapDrawable( getApplicationContext().getResources(), Bitmap.createBitmap(0, 0, Bitmap.Config.ARGB_8888) ));
This gave me an error that a Bitmap must have a width and height bigger than 0.
Right now I use:
[code]myPopupWindow.setBackgroundDrawable(new BitmapDrawable( getApplicationContext().getResources(), Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888) ));
And it works. But it just seems a bit wrong to use a 1x1 pixel Bitmap instead of a completely empty one like I want to. Is there another way to actually use an empty BitmapDrawable, instead of one that is 1 by 1 pixels?
2down voteaccepted | Ok, instead of[code]myPopupWindow.setBackgroundDrawable(new BitmapDrawable()); OR [code]myPopupWindow.setBackgroundDrawable(new BitmapDrawable( getApplicationContext().getResources(), Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888) )); I just use a background-color that I want to set to the PopupWindow. So for example, one of my PopupWindows just had a few Images without margins in between them, so I just used a Transparent background for it: [code]myPopupWindow.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); And for another one I wanted to use a white background anyway, so I've used: [code]myPopupWindow.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.WHITE)); |
相关文章推荐
- 从drawable下面的图片 创建一个Bitmap
- 通过创建一个位图的XY Chart来学习Android绘图类Rect,Paint,Bitmap,Canvas(附源码)
- 通过创建一个位图的XY Chart来学习Android绘图类Rect,Paint,Bitmap,Canvas(附源码)
- Android中BitmapDrawable的一个bug
- [转]通过创建一个位图的XY Chart来学习Android绘图类Rect,Paint,Bitmap,Canvas(附源码)
- android如何获取res文件夹下drawable文件夹下的图片资源文件转成一个BitMap对象
- 通过创建一个位图的XY Chart来学习Android绘图类Rect,Paint,Bitmap,Canvas(附源码)
- Android开发:创建一个可供编辑的图片(bitmap)
- Android中Drawable Bitmap Canvas Paint之间区别
- AE创建一个空白的Shapefile
- Android中几种图像特效处理的小技巧,比如圆角,倒影,还有就是图片缩放,Drawable转化为Bitmap,Bitmap转化为Drawable等等
- Android学习之四:创建一个简单程序
- 创建一个android activity
- AE创建一个空白的Shapefile (转载)
- 找到一个在Android上创建阻塞式模态对话框的方法
- [Android] bitmap/drawable/byte的转换和获取圆角/倒影图片
- 为什么android中的AlertDialog要用一个内部的static class Builder来创建呢?
- 已知一个一维数组:BYTE imageArray[width * height], 怎样在VC++2008的MFC中,用GDI+,创建一个Bitmap对象,与该数组建立关联?
- Android 性能优化一例(Bitmap创建时会调用gc)