我用过PopupWindow.使用此PopupWindow,我将BackgroundDrawable设置为空的BitmapDrawable.
当我使用以下代码时,它会给出一个弃用的警告:
myPopupWindow.setBackgroundDrawable(new BitmapDrawable());
Run Code Online (Sandbox Code Playgroud)
所以我改成了:
myPopupWindow.setBackgroundDrawable(new BitmapDrawable(
getApplicationContext().getResources(),
Bitmap.createBitmap(0, 0, Bitmap.Config.ARGB_8888)
));
Run Code Online (Sandbox Code Playgroud)
这给了我一个错误,即Bitmap的宽度和高度必须大于0.
现在我使用:
myPopupWindow.setBackgroundDrawable(new BitmapDrawable(
getApplicationContext().getResources(),
Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888)
));
Run Code Online (Sandbox Code Playgroud)
它有效.但是使用1x1像素的Bitmap而不是像我想要的那样完全空的Bitmap似乎有点不对.还有另一种实际使用空BitmapDrawable的方法,而不是1 x 1像素的方法吗?
由于BitmapDrawable不推荐使用无参数构造函数,我们必须为构造函数提供资源ID.
BitmapDrawable bitmapDrawable = new BitmapDrawable(res, bmap);
Run Code Online (Sandbox Code Playgroud)
res一般在哪里getResources().
为什么构造函数需要它,如果我们使用通用图像缓存,我们如何定义该值?
android android-resources android-drawable bitmapdrawable android-bitmap
在我的应用程序中使用自定义PopupWindow在哪里使用
popup.setBackgroundDrawable(new BitmapDrawable());
Run Code Online (Sandbox Code Playgroud)
方法.现在它已被弃用,如果没有这种方法,我就无法为弹出窗口提供背景信息.我从文章中读到它的替代方案
popup.setsetBackgroundDrawable(new BitmapDrawable(Context.Resources,Drawable);
Run Code Online (Sandbox Code Playgroud)
但在这里我没有使用任何drawable我的popUp.我的代码在下面给出了我自定义Popupwindow的位置,这里是为了解决这个问题.
@Override
public void onWindowFocusChanged(boolean hasFocus) {
int[] location = new int[2];
Button button = (Button) findViewById(R.id.VBG_img_pin_x);
// Get the x, y location and store it in the location[] array
// location[0] = x, location[1] = y.
button.getLocationOnScreen(location);
// Initialize the Point with x, and y positions
p = new Point();
p.x = location[0];
p.y = location[1];
}
// The method that displays the popup.
private void showPopup(final Activity context, Point p) {
// …Run Code Online (Sandbox Code Playgroud) 在我的项目中,一个位图充满了文本和另一个位图,将文本添加到位图的方法返回一个BitmapDrawable。
我想将此BitmapDrawable保存为pdf文件,以便可以通过电子邮件发送原始的位图,并添加文本和其他图像。
为此,我需要一个常规的位图而不是BitmapDrawable。我似乎找不到任何答案,因为我没有在drawable文件夹中对drawable的引用,我只有一个BitmapDrawable可以使用。
有什么想法吗?