美文网首页
Android开发笔记

Android开发笔记

作者: 扎心的_老铁 | 来源:发表于2021-05-08 13:28 被阅读0次

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

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

    2.Guideline的使用

    <androidx.constraintlayout.widget.Guideline
                android:id="@+id/gl"
                android:layout_width="wrap_content"
                android:orientation="vertical"
                app:layout_constraintGuide_percent="0.5"
                android:layout_height="wrap_content"/>
    

    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开发笔记

          本文链接:https://www.haomeiwen.com/subject/bxsudltx.html