1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.PopupWindow
object HomePromptView { @JvmStatic fun showTipPopView(view: View, typedStr: String?): PopupWindow {
val rootView = LayoutInflater.from(view.context).inflate(R.layout.home_prompt_layout, null) val promptTv = rootView.findViewById<TextViewSwitcher>(R.id.tv_prompt) promptTv.setTextList(typedStr?.split("|")) rootView.isClickable = false
val popTipWid = PopupWindow( rootView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT ) popTipWid.isTouchable = false
try { popTipWid.showAtLocation(view.rootView, 0, 0, 0) layoutPromptLocation(promptTv, view)
view.addOnLayoutChangeListener { view, i, i2, i3, i4, i5, i6, i7, i8 -> layoutPromptLocation(promptTv, view) } } catch (e: Exception) { e.printStackTrace() } return popTipWid }
private fun layoutPromptLocation( promptTv: TextViewSwitcher, view: View ) { try { val params = promptTv.layoutParams as ViewGroup.MarginLayoutParams val location = IntArray(2) view.getLocationInWindow(location) params.topMargin = location[1] - UiUtils.getStatusBarHeight(view.context) + UiUtils.dip2px(4) params.leftMargin = location[0] + UiUtils.dip2px(25) promptTv.layoutParams = params } catch (e: Exception) { e.printStackTrace() } }
@JvmStatic fun dismissTipPopView(popTipWid: PopupWindow?) { popTipWid?.dismiss() }
}
|