I'm trying to add a custom ListPopupWindow
to a TextView
wrapped in a TextInputLayout
. The TextView
has an OnClick listener that creates and shows the ListPopupWindow
. Effectively I'm working on a custom Spinner.
If I change the TextInputLayout
to a LinearLayout
the ListPopupWindow
displays correctly. Otherwise, the visual error is extra padding at the bottom of the popup.
XML:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.project.CustomTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.TextInputLayout>
CustomTextView:
@Override
public void onClick(View v) {
ArrayList<String> list = new ArrayList<>();
list.add("Item 1");
list.add("Item 2");
ListPopupWindow popup = new ListPopupWindow(getContext());
popup.setAnchorView(this);
popup.setHeight(ListPopupWindow.WRAP_CONTENT);
popup.setAdapter(new ArrayAdapter<>(getContext(), R.layout.support_simple_spinner_dropdown_item, list));
popup.show();
}
Result:
(This is just my non-generic implementation I'm working on. Notice the clipped bottom of the list. There is a ~30dp padding there that can't be removed).