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>
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