美文网首页
CTextView在项目中的应用

CTextView在项目中的应用

作者: 码农朱同学 | 来源:发表于2019-05-07 15:12 被阅读0次
银行精选列表页

处理如上图这5种情况

1,CDrawablePadding处理原生DrawablePadding对drawableRight和drawableLeft处理的bug

 <LinearLayout
     android:layout_width="match_parent"
     android:layout_height="@dimen/cbase_dp_50"
     android:background="@color/cbase_white_color"
     android:gravity="center_vertical"
     android:orientation="horizontal"
     android:visibility="visible">

     <com.creditwealth.bankfinancing.widget.CTextView
         android:id="@+id/tv_tab_profit"
         android:layout_width="0dp"
         android:layout_height="match_parent"
         android:layout_weight="1"
         android:drawableRight="@drawable/bf_arrow_down_sort"
         android:gravity="center"
         android:text="收益"
         android:textColor="@color/bf_select_text_color"
         android:textSize="@dimen/cbase_dp_15"
         android:textStyle="bold"
         app:bf_CDrawablePadding="10dp" />

     <com.creditwealth.bankfinancing.widget.CTextView
         android:id="@+id/tv_tab_type"
         android:layout_width="0dp"
         android:layout_height="match_parent"
         android:layout_weight="1"
         android:drawableRight="@drawable/bf_arrow_down_float"
         android:text="产品类型"
         android:textColor="@color/bf_select_text_color"
         android:textSize="@dimen/cbase_dp_15"
         android:textStyle="bold"
         app:bf_CDrawablePadding="10dp" />

     <com.creditwealth.bankfinancing.widget.CTextView
         android:id="@+id/tv_tab_bank"
         android:layout_width="0dp"
         android:layout_height="match_parent"
         android:layout_weight="1"
         android:drawableRight="@drawable/bf_arrow_down_float"
         android:text="银行"
         android:textColor="@color/bf_select_text_color"
         android:textSize="@dimen/cbase_dp_15"
         android:textStyle="bold"
         app:bf_CDrawablePadding="10dp" />


 </LinearLayout>

2,处理空心button/textview

在xml中使用:

    <com.creditwealth.bankfinancing.widget.CTextView
        android:layout_width="100dp"
        android:layout_height="30dp"
        android:text="明日1:00开抢"
        android:textColor="@color/cbase_red_color"
        android:textSize="@dimen/cbase_sp_10"
        app:bf_CStrokeColor="@color/cbase_red_color"
        app:bf_CStrokeWidth="1dp"
        app:bf_CAngleCorner="2dp"/>
  • bf_CStrokeColor表示外面轮廓线的颜色
  • bf_CStrokeWidth表示外面轮廓线的宽度
  • bf_CAngleCorner表示圆角弧度

动态生成:

 tagText.initStrokeAttr(
     ContextCompat.getColor(ctx, R.color.bf_main),
     2,
     ScreenUtil.dimen2px(ctx, R.dimen.cbase_dp_1)
 )

3,处理实心button/textview

在xml中使用:

    <com.creditwealth.bankfinancing.widget.CTextView
        android:layout_width="100dp"
        android:layout_height="30dp"
        android:text="明日1:00开抢"
        android:textColor="@color/white"
        android:textSize="@dimen/cbase_sp_10"
        app:bf_CSolidColor="@color/cbase_red_color"
        app:bf_CAngleCorner="2dp"/>
  • bf_CSolidColor表示实心颜色
  • bf_CAngleCorner表示圆角弧度

动态生成:

 tagText.initSolidAttr(
  ContextCompat.getColor(ctx, R.color.white),
  ContextCompat.getColor(ctx, R.color.bf_main),
  ScreenUtil.dimen2px(ctx, R.dimen.cbase_dp_1)
 )

4,button/textview中倾斜字体

使用:

  <com.creditwealth.bankfinancing.widget.CTextView
      android:id="@+id/tv_sale_desc"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:padding="10dp"
      android:text="明日1:00开抢"
      android:textColor="@color/cbase_red_color"
      android:textSize="@dimen/cbase_sp_10"
      app:bf_CRotateDegree="15"
      app:layout_constraintBottom_toBottomOf="@+id/iv_sale_status"
      app:layout_constraintLeft_toLeftOf="@+id/iv_sale_status"
      app:layout_constraintRight_toRightOf="@+id/iv_sale_status"
      app:layout_constraintTop_toTopOf="@+id/iv_sale_status" />
      app:bf_CRotateDegree="15"

表示倾斜角度为15度

5,button/textview中字符串中特定字符串字体大小与颜色

可以直接在xml中预览:

    <com.creditwealth.bankfinancing.widget.CTextView
        android:id="@+id/tv_expect_profit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/cbase_dp_10"
        android:textColor="@color/bf_main"
        android:textSize="@dimen/cbase_sp_27"
        app:bf_CSpecialTextReg="%"
        app:bf_CSpecialTextSize="6sp"
        app:layout_constraintLeft_toLeftOf="@+id/tv_product_title"
        app:layout_constraintTop_toBottomOf="@+id/fl_tag_container"
        android:text="4.10%" />
在xml中预览

也可直接使用代码:

 //CTextView自带函数 处理这种特殊字符串的特殊颜色或大小
 tv_expect_profit.setSpecialText(item.incValue, "%", 0, 14)

内部函数实现:

    //暴露出来的函数用来 处理特殊字符串的特殊颜色或大小
    fun setSpecialText(srcStr: String, specialTextReg: String, valueColor: Int, size: Int) {
        var valueColor = valueColor

        if (TextUtils.isEmpty(srcStr))
            return

        if (TextUtils.isEmpty(specialTextReg) || !srcStr.contains(specialTextReg))
            return

        if (valueColor == 0) {
            valueColor = this.currentTextColor
        }

        val resultSpan = SpannableString(srcStr)

        val p = Pattern.compile(specialTextReg)
        val m = p.matcher(srcStr)

        while (m.find() && specialTextReg != "") {

            resultSpan.setSpan(
                ForegroundColorSpan(valueColor),
                m.start(), m.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
            )

            if (size != 0) {
                resultSpan.setSpan(AbsoluteSizeSpan(size, true), m.start(), m.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
            }
        }

        this.text = resultSpan
        return
    }

相关文章

  • CTextView在项目中的应用

    处理如上图这5种情况 1,CDrawablePadding处理原生DrawablePadding对drawable...

  • sessionStorage在项目中的应用

    本地存储Cookie(局限性):用户可以禁用cookie,最多只能存储4kb,cookie有过期时间的(一般我们设...

  • CAS在项目中的应用

    模拟一般抢购活动中需要加锁的程序,采用synchronized锁与CAS锁,比较二者的性能。说明二者的区别,并指出...

  • Elasticsearch在项目中的应用

    需求背景 项目中需要对外提供门店级别的业务库存查询接口,现场sku数为5W+,门店数量400+,业务库存记录约20...

  • H5页面中CSS3动画的性能优化

    CSS3动画应用很广,尤其是在H5项目中,炫酷的交互效果可以给产品带来更好的体验,更能吸引用户。然而在应用的时候,...

  • Dubbo在项目中的应用(一)

    Dubbo作为分布式服务治理框架在企业级应用开发中运用的特别广泛,它打破了传统垂直项目架构的开发模式,将各个模块更...

  • RAC在项目中的初步应用

    首先简单介绍一下RAC是个什么东西。RAC全称ReactiveCocoa,是GitHub开源的一个函数响应式编程(...

  • runtime在实际项目中的应用

    平时觉得runtime都是大神用的,但是通过慢慢的学习,在实际项目中运用runtime,某些时候确实感觉挺牛逼的....

  • markdown在oc项目中的应用

    Markdown 是一种轻量级标记语言,它允许人们使用易读易写的纯文本格式编写文档,然后转换成格式丰富的HTML页...

  • 关于Cookie 在项目中的应用

    项目用到了 把用户信息保存在 cookie 中,类似浏览器记录用户信息一样,然后请求的接口从cookie中获取 当...

网友评论

      本文标题:CTextView在项目中的应用

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