美文网首页
SupertextView第三方库中的shape的运用

SupertextView第三方库中的shape的运用

作者: 行走的影子_4eba | 来源:发表于2023-04-16 14:41 被阅读0次

在我们项目开发中,有许多时候需要给背景设置圆角,颜色等场景。常见的做法是在drawable中设置对应的背景,但是如果项目中频繁用到,并且只是颜色变化,那样会很麻烦。
那么废话不说,我们先引入SupertextView
在项目的build.gradle里添加
implementation 'com.github.lygttpod:SuperTextView:2.4.6'


image.png

引入后会有这么多控件可供选择
用法很简单

...
<com.allen.library.shape.ShapeConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:shapeCornersRadius="@dimen/dp12"
app:shapeSolidColor="@color/white"
android:padding="20dp">

<TextView
    android:id="@+id/tv_title"
    style="@style/DialogTitleTextStyle"
    android:layout_width="match_parent"
    android:gravity="center"
    android:lineHeight="28dp"
    app:layout_constraintTop_toTopOf="parent"
    tools:text="标题" />

<TextView
    android:id="@+id/tv_content"
    style="@style/LightBlackTextStyle"
    android:layout_width="match_parent"
    android:layout_marginTop="12dp"
    android:gravity="center"
    android:lineHeight="22dp"
    android:textColor="@color/black"
    android:textSize="16sp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/tv_title"
    tools:text="对话框内容,超长可换行" />

<com.allen.library.shape.ShapeButton
    android:id="@+id/btn_left"
    android:layout_height="@dimen/huge_36"
    android:layout_width="0dp"
    android:gravity="center"
    android:layout_marginTop="24dp"
    android:layout_marginEnd="@dimen/dp12"
    app:shapeSolidColor="@color/white"
    app:shapeCornersRadius="@dimen/dp12"
    app:shapeStrokeColor="@color/accentBlue"
    app:shapeStrokeWidth="1dp"

    android:text="取消"
    app:layout_constraintEnd_toStartOf="@+id/btn_right"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/tv_content"
    app:layout_constraintWidth_percent="0.45" />

<com.allen.library.shape.ShapeButton
    android:gravity="center"
    android:id="@+id/btn_right"
    android:layout_height="@dimen/huge_36"
    android:layout_width="0dp"
    android:layout_marginTop="24dp"
    android:text="确认"
    android:textColor="@color/white"
    app:shapeSolidColor="@color/accentBlue"
    app:shapeCornersRadius="@dimen/dp12"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/btn_left"
    app:layout_constraintTop_toBottomOf="@+id/tv_content"
    app:layout_constraintWidth_percent="0.45" />

</com.allen.library.shape.ShapeConstraintLayout>
...

重点就是通过属性来配置背景
这点和drawable文件的设置是一一对应的。
所以没有什么学习成本
我们看下效果


image.png

不需要额外引用了,效果很直观

相关文章

网友评论

      本文标题:SupertextView第三方库中的shape的运用

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