Android开发笔记

1.控件点击加水波纹效果

android:background="?android:attr/selectableItemBackground"//有边界
android:background="?android:attr/selectableItemBackgroundBorderless"//无边界

2.Guideline的使用


3.Spannable富文本

private fun setDescText() {
        val str =
            "By creating your account you agree to your personal data being stored and processed according to our Service-Agreement and Privacy-Policy."
        val start1 = str.indexOf("Service-Agreement")
        val end1 = start1 + "Service-Agreement".length
        val spannable = SpannableStringBuilder(str)
        spannable.setSpan(
            ForegroundColorSpan(ContextCompat.getColor(requireContext(), R.color.btn_blue)),
            start1,
            end1,
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
        )
        val start2 = str.indexOf("Privacy-Policy.")
        val end2 = start2 + "Privacy-Policy.".length
        spannable.setSpan(
            ForegroundColorSpan(ContextCompat.getColor(requireContext(), R.color.btn_blue)),
            start2,
            end2,
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
        )
        mBinding.tvDescroption.movementMethod = LinkMovementMethod.getInstance()
        //设置点击事件1
        spannable.setSpan(object : ClickableSpan() {
            override fun onClick(widget: View) {
                LogUtils.d("click1")
                openWebPage(1)
            }
        }, start1, end1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
        //设置点击事件2
        spannable.setSpan(object : ClickableSpan() {
            override fun onClick(widget: View) {
                LogUtils.d("click2")
                openWebPage(2)
            }
        }, start2, end2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
        mBinding.tvDescroption.text = spannable
    }

4.MaterialButton使用

你可能感兴趣的:(Android开发笔记)