Getting following crash while showing a Dialog box in android9 and below. Above android version 9 its working fine

Viewed 24

trying to show a dialog on button click but getting java.lang.IllegalArgumentException: color and position arrays must be of equal length crash in android 9 and below. below is my Dialog box code

sendPackagesDiolog = Dialog(this)
sendPackagesDiolog?.requestWindowFeature(Window.FEATURE_NO_TITLE)
sendPackagesDiolog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
sendPackagesDiolog?.setContentView(R.layout.send_packages_additem_popup)
sendPackagesDiolog?.window?.setLayout(
    WindowManager.LayoutParams.MATCH_PARENT,
    WindowManager.LayoutParams.MATCH_PARENT
)
// sendPackagesDiolog?.window?.attributes?.windowAnimations = R.style.diologIntertnet
sendPackagesDiolog?.setCanceledOnTouchOutside(true)
sendPackagesDiolog?.show()
val disable_gradientRl =
    sendPackagesDiolog?.findViewById<RelativeLayout>(R.id.disable_gradientRl)
val restrictiontxt = sendPackagesDiolog?.findViewById<TextView>(R.id.restrictiontxt)
val restrictionLl = sendPackagesDiolog?.findViewById<LinearLayout>(R.id.restrictionLl)

restrictionLl!!.visibility = View.VISIBLE
dynamicTextForCenter(
    restrictiontxt!!,
    "Delivery of ",
    "alcohal, tobacco or any illegal items ",
    "prohibited by the Gov. of India."
)
}

fun dynamicTextForCenter(
    view: TextView,
    start_str: String?,
    change_color_str: String,
    end_str: String?
) {
    view.text = ""
    val str = SpannableString(change_color_str)
    str.setSpan(
        ForegroundColorSpan(Color.GREEN),
        0,
        str.length,
        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
    )
    str.setSpan(StyleSpan(Typeface.NORMAL), 0, str.length, 0)
    view.append(start_str)
    view.append(str)
    view.append(end_str)
}
0 Answers
Related