Android开发笔记

时间:2021-7-9 作者:qvyue

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使用

声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:qvyue@qq.com 进行举报,并提供相关证据,工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。