В моем приложении, используя пользовательский PopupWindow, где я с помощьюПользовательский PopupWindow с BitmapDrawable устаревшего метода
popup.setBackgroundDrawable(new BitmapDrawable());
метода. Теперь он устарел здесь, и без этого метода я не могу предоставить фон для своего всплывающего окна. Я прочитал из статьи, что его альтернатива
popup.setsetBackgroundDrawable(new BitmapDrawable(Context.Resources,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) {
// Display display = getWindowManager().getDefaultDisplay();
DisplayMetrics display = this.getResources().getDisplayMetrics();
int width = display.widthPixels;
int height = display.heightPixels;
// int width = display.getWidth(); // deprecated
// int height = display.getHeight(); // deprecated
int popupWidth = width/2;
int popupHeight = height;
ChatUtils.getScreenHeight(getBaseContext());
// Inflate the popup_layout.xml
LinearLayout viewGroup = (LinearLayout) context
.findViewById(R.id.popup);
LayoutInflater layoutInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.popup_layout, viewGroup);
onSetAlpha(240, layout);
// layout.setAlpha((float) 0.95);
// Creating the PopupWindow
final PopupWindow popup = new PopupWindow(context);
popup.setTouchable(true);
popup.setFocusable(false);
popup.setOutsideTouchable(true);
popup.setContentView(layout);
popup.setWidth(popupWidth);
popup.setHeight(popupHeight);
popup.setFocusable(true);
// Some offset to align the popup a bit to the right, and a bit down,
// relative to button's position.
// Clear the default translucent background
popup.setBackgroundDrawable(new BitmapDrawable());
}
'popup.setBackgroundDrawable (null);' должен иметь тот же эффект. Можете ли вы попробовать? – Blackbelt
@Blackbelt спасибо за ваш комментарий. Оно работает. Ответьте на это в моем ответе, поэтому я могу принять его в качестве моего ответа. –