如何为弹出窗口 window 提供弯曲的边缘并为弹出窗口提供明显的阴影 window
How to give curved edges for a popup window and a noticeable shadow to the popup window
我必须为弹出窗口提供弯曲的边缘 window 弹出窗口有明显的阴影 window 工作正常但没有弯曲的边缘和明显的背景阴影 window并且弹出窗口 window 在 b/w 中没有显示明显的 space 他们
DisplayMetrics dm=new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width=dm.widthPixels;
int height=dm.heightPixels;
getWindow().setLayout((int)(width*1.0),(int)(height*.8));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
getWindow().setElevation(40);
}
答案很简单,试试这个:-
首先创建一个自定义弹出窗口并为其指定一个自定义布局。
private fun channelPopup(){
// addDummyProfile()
channelDialog = Dialog(context)
channelDialog!!.requestWindowFeature(Window.FEATURE_NO_TITLE)
val lp = channelDialog!!.getWindow()!!.getAttributes()
val window = channelDialog!!.getWindow()
window!!.setGravity(Gravity.CENTER)
channelDialog!!.getWindow()!!.setAttributes(lp)
channelDialog!!.getWindow()!!.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
channelDialog!!.setCanceledOnTouchOutside(true)
channelDialog!!.setCancelable(true)
channelDialog!!.setContentView(R.layout.exitsing_channel_layout)
val tv_videos_no: TextView = channelDialog!!.findViewById(R.id.tv_videos_no) as TextView
val recycler_channel = channelDialog!!.findViewById<RecyclerView>(R.id.recycler_channel)
recycler_channel!!.layoutManager= LinearLayoutManager(context)
channelAdapter = ChannelAdapter(tv_videos_no)
recycler_channel!!.adapter = channelAdapter
channelDialog!!.show()
}
然后在您的布局中为父布局提供自定义背景,创建一个新的可绘制对象 xml 并粘贴:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="@color/white"/>
<corners
android:radius="30dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
然后将此可绘制对象 XML 设置为自定义弹出布局的父布局的背景 XML。
在自定义弹出 Java 文件中添加此行。
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
我必须为弹出窗口提供弯曲的边缘 window 弹出窗口有明显的阴影 window 工作正常但没有弯曲的边缘和明显的背景阴影 window并且弹出窗口 window 在 b/w 中没有显示明显的 space 他们
DisplayMetrics dm=new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width=dm.widthPixels;
int height=dm.heightPixels;
getWindow().setLayout((int)(width*1.0),(int)(height*.8));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
getWindow().setElevation(40);
}
答案很简单,试试这个:-
首先创建一个自定义弹出窗口并为其指定一个自定义布局。
private fun channelPopup(){
// addDummyProfile()
channelDialog = Dialog(context)
channelDialog!!.requestWindowFeature(Window.FEATURE_NO_TITLE)
val lp = channelDialog!!.getWindow()!!.getAttributes()
val window = channelDialog!!.getWindow()
window!!.setGravity(Gravity.CENTER)
channelDialog!!.getWindow()!!.setAttributes(lp)
channelDialog!!.getWindow()!!.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
channelDialog!!.setCanceledOnTouchOutside(true)
channelDialog!!.setCancelable(true)
channelDialog!!.setContentView(R.layout.exitsing_channel_layout)
val tv_videos_no: TextView = channelDialog!!.findViewById(R.id.tv_videos_no) as TextView
val recycler_channel = channelDialog!!.findViewById<RecyclerView>(R.id.recycler_channel)
recycler_channel!!.layoutManager= LinearLayoutManager(context)
channelAdapter = ChannelAdapter(tv_videos_no)
recycler_channel!!.adapter = channelAdapter
channelDialog!!.show()
}
然后在您的布局中为父布局提供自定义背景,创建一个新的可绘制对象 xml 并粘贴:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="@color/white"/>
<corners
android:radius="30dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
然后将此可绘制对象 XML 设置为自定义弹出布局的父布局的背景 XML。
在自定义弹出 Java 文件中添加此行。
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));