我想在菜单中显示带有Recycler视图的弹出窗口。
弹出窗口的右上角-> 我显示的是排序箭头图标。
所以我将弹出窗口设置为透明背景,并以白色背景显示回收器视图。
`menu.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));`
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvCategory"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:elevation="10dp"
android:background="@drawable/popup_bg"/>
在回收器视图中,立面是不工作的。它看起来不像没有边框和升降的菜单。弹出式
请帮我解决这个问题。
为了得到你想要的外观,你可以像这样修改你的弹出窗口xml。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="10dp"
app:cardCornerRadius="6dp"
app:cardElevation="6dp">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvCategory"
android:layout_width="match_parent"
android:layout_height="200dp"
android:paddingStart="10dp"
android:paddingTop="5dp"
android:paddingEnd="1dp"
android:paddingBottom="5dp"
android:clipToPadding="false"
android:scrollbars="vertical" />
</androidx.cardview.widget.CardView>
</LinearLayout>
在你初始化你的弹出窗口的代码中,它应该是这样的(这里mContext是你的Activity)。
PopupWindow mPopup = new PopupWindow(mContext);
View popUpView = mContext.getLayoutInflater().inflate(R.layout.your_popup_xml, null);
// other initializations
mPopup.setBackgroundDrawable(null);
mPopup.setContentView(popUpView);
mPopup.setFocusable(true);
mPopup.setClippingEnabled(true);