2

My PopupWindow is working perfectly fine on my API 28,29 Emulators, but not sure why it's not showing any view on my API 19 real device. The window is definitely created though because when I click on the button that inflates the view, it is focused.

My custom popup window:

    public class MessagesMoreMenu extends PopupWindow {

    private static final String TAG = "MessagesMoreMenu";

    private Context mContext;
    public MessagesMoreMenu(Context context) {
        super(context);
        this.mContext = context;
        setupView();
    }

    private void setupView(){
        View view = LayoutInflater.from(mContext)
                .inflate(R.layout.popupmenu_messagesmoremenu, null);
        ButterKnife.bind(this, view);

        setContentView(view);
    }
}

Usage of it:

    private void inflateMoreMenu(View view){
         PopupWindow popupWindow = new MessagesMoreMenu(mContext);
         popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
         popupWindow.setOutsideTouchable(true);
         popupWindow.setFocusable(true);
         popupWindow.showAsDropDown(view);
    }

XML layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <TextView
        android:id="@+id/popupmenu_messagesmore_report"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Report"
        android:padding="16dp"
        app:drawableLeftCompat="@drawable/icon_messages_report"
        android:textColor="@color/colorBlackFont"
        android:layout_alignParentTop="true"
        android:gravity="center_vertical"
        android:drawablePadding="16dp"/>


    <TextView
        android:id="@+id/popupmenu_messagesmore_block"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawablePadding="16dp"
        android:padding="16dp"
        android:text="Block"
        app:drawableLeftCompat="@drawable/icon_alertdialog_block"
        android:textColor="@color/colorBlackFont"
        android:layout_below="@+id/popupmenu_messagesmore_report"
        android:gravity="center_vertical"/>

</RelativeLayout>
6
  • Do you get any error. Try on a real device with API 28,29 or an emulator with API 19. Also, what is mContext here? Is it getApplicationContext() or ClassName.this? Commented Jan 13, 2020 at 8:02
  • classname.this and no errors Commented Jan 13, 2020 at 8:03
  • Please try on a real device with API 28,29 or an emulator with API 19. I will try to re-run the code on my end. Commented Jan 13, 2020 at 8:09
  • @davids. please show your layout xml Commented Jan 13, 2020 at 8:18
  • @davids. give the RelativeLayout an exact dp or match_parent to try Commented Jan 13, 2020 at 8:39

2 Answers 2

1

Very weird but adding this fixed my problem...

popupWindow.setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

https://stackoverflow.com/a/51177435/11110509

This is not needed on my other non API 19 devices

Sign up to request clarification or add additional context in comments.

Comments

0

please try

popupWindow.showAtLocation(mRelativeLayout, Gravity.CENTER,0,0);

here mRelativeLayout is a view reference from your activity/fragment

2 Comments

tried, still not displaying on api 19. It works on the others though

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.