作者 zhangji

popupWindow遮罩层还未处理完

  1 +package com.br_technology.securitytrain_master.expand
  2 +
  3 +import android.content.res.Resources
  4 +
  5 +/**
  6 + * createTime:2021/7/30 10:50
  7 + * auth:张继
  8 + * des:
  9 + */
  10 +
  11 +fun Int.dp2px(): Int {
  12 + val density = Resources.getSystem().displayMetrics.density
  13 + return (density * this + 0.5f).toInt()
  14 +}
  15 +fun Int.px2dp(): Int {
  16 + val density = Resources.getSystem().displayMetrics.density
  17 + return (this/density + 0.5f).toInt()
  18 +}
@@ -8,6 +8,8 @@ import androidx.core.content.ContextCompat @@ -8,6 +8,8 @@ import androidx.core.content.ContextCompat
8 import com.br_technology.securitytrain_master.R 8 import com.br_technology.securitytrain_master.R
9 import com.br_technology.securitytrain_master.databinding.PopClassifyBinding 9 import com.br_technology.securitytrain_master.databinding.PopClassifyBinding
10 import com.br_technology.securitytrain_master.expand.addItemDecoration 10 import com.br_technology.securitytrain_master.expand.addItemDecoration
  11 +import com.br_technology.securitytrain_master.expand.dp2px
  12 +import com.br_technology.securitytrain_master.expand.screenHeight
11 import com.br_technology.securitytrain_master.expand.screenWidth 13 import com.br_technology.securitytrain_master.expand.screenWidth
12 import com.br_technology.securitytrain_master.ui.home.adapter.TextCourseTypeAdapter 14 import com.br_technology.securitytrain_master.ui.home.adapter.TextCourseTypeAdapter
13 import com.br_technology.securitytrain_master.view.listener.OnItemClickListener 15 import com.br_technology.securitytrain_master.view.listener.OnItemClickListener
@@ -26,9 +28,19 @@ class ClassifyPop(context: Activity) : PopupWindow(context) { @@ -26,9 +28,19 @@ class ClassifyPop(context: Activity) : PopupWindow(context) {
26 init { 28 init {
27 contentView = binding.root 29 contentView = binding.root
28 width = contentView.screenWidth() 30 width = contentView.screenWidth()
29 - height = height  
30 - setBackgroundDrawable(ContextCompat.getDrawable(context, R.color.white)) 31 + height = 252.dp2px()
  32 + setBackgroundDrawable(ContextCompat.getDrawable(context, android.R.color.transparent))
  33 + isOutsideTouchable = false
31 34
  35 +// val attributes = context.window.attributes
  36 +// attributes.alpha = 0.5f
  37 +// context.window.attributes = attributes
  38 +//
  39 +// setOnDismissListener {
  40 +// val attributes = context.window.attributes
  41 +// attributes.alpha = 1f
  42 +// context.window.attributes = attributes
  43 +// }
32 44
33 binding.apply { 45 binding.apply {
34 courseType.addItemDecoration(3, 14) 46 courseType.addItemDecoration(3, 14)
@@ -53,6 +65,12 @@ class ClassifyPop(context: Activity) : PopupWindow(context) { @@ -53,6 +65,12 @@ class ClassifyPop(context: Activity) : PopupWindow(context) {
53 }) 65 })
54 courseType.adapter = textCourseTypeAdapter 66 courseType.adapter = textCourseTypeAdapter
55 textCourseTypeAdapter.addList(list) 67 textCourseTypeAdapter.addList(list)
  68 +
  69 + complete.setOnClickListener {
  70 + dismiss()
  71 + }
  72 +
  73 +
56 } 74 }
57 } 75 }
58 76
@@ -29,4 +29,5 @@ @@ -29,4 +29,5 @@
29 android:text="完成" 29 android:text="完成"
30 android:textColor="@color/white" 30 android:textColor="@color/white"
31 android:textSize="15sp" /> 31 android:textSize="15sp" />
  32 +
32 </LinearLayout> 33 </LinearLayout>