1.https://github.com/JavaNoober/BackgroundLibrary
implementation 'com.noober.backgorund:core:1.0.5'
在Activity/Fragment的onCreate()之前调用 BackgroundLibrary.inject(this);
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
android:orientation="vertical"
android:padding="10dp"
tools:context=".MainActivity"
tools:ignore="MissingPrefix">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:text="直接添加自定义属性,设置背景shape:" />
<TextView
android:layout_width="130dp"
android:layout_height="36dp"
android:gravity="center"
android:text="TextView"
android:textColor="#8c6822"
android:textSize="20sp"
app:corners_radius="4dp"
app:solid_color="#E3B666"
app:stroke_color="#8c6822"
app:stroke_width="2dp" />
<Button
android:layout_width="130dp"
android:layout_height="36dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:padding="0dp"
android:text="Button"
android:textColor="#4F94CD"
android:textSize="20sp"
app:corners_radius="20dp"
app:gradient_angle="0"
app:gradient_endColor="#4F94CD"
app:gradient_startColor="#63B8FF"
app:shape="rectangle" />
<Button
android:layout_width="300dp"
android:layout_height="50dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:padding="0dp"
android:text="确认"
android:textColor="@android:color/white"
android:textSize="20sp"
app:corners_radius="20dp"
app:gradient_angle="0"
app:gradient_centerColor="#CD4F39"
app:gradient_endColor="#CD2626"
app:gradient_startColor="#CD5B45"
app:shape="rectangle" />
<TextView
app:corners_radius="4dp"
app:gradient_useLevel="true"
app:solid_color="#E3B666"
app:stroke_color="#8c6822"
app:stroke_dashGap="5dp"
app:stroke_dashWidth="10dp"
app:stroke_width="2dp"
android:layout_width="130dp"
android:layout_height="36dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="TextView"
android:textColor="#8c6822"
android:textSize="20sp"/>
<Button
android:layout_width="300dp"
android:layout_height="50dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:padding="0dp"
android:text="有点击反馈的按钮"
android:textColor="@android:color/white"
android:textSize="20sp"
app:corners_radius="20dp"
app:shape="rectangle"
app:unpressed_color="#7CFC00"
app:pressed_color="#7CCD7C"/>
<View
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:textColor="#8c6822"
android:textSize="20sp"
app:shape="rectangle"
app:solid_color="#E3B666"
app:stroke_color="#8c6822"
app:stroke_width="2dp"
app:stroke_dashGap="5dp"
app:stroke_dashWidth="10dp"/>
<Button
android:layout_width="300dp"
android:layout_height="50dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:padding="0dp"
android:text="有波纹触摸反馈的按钮"
android:textColor="@android:color/white"
android:textSize="20sp"
app:stroke_color="#8c6822"
app:stroke_width="2dp"
app:corners_radius="20dp"
app:ripple_enable="true"
app:ripple_color="#71C671"
app:solid_color="#7CFC00"
/>
</LinearLayout>
补充:
- <corners //定义圆角
- android:radius="dimension" //全部的圆角半径
- android:topLeftRadius="dimension" //左上角的圆角半径
- android:topRightRadius="dimension" //右上角的圆角半径
- android:bottomLeftRadius="dimension" //左下角的圆角半径
- android:bottomRightRadius="dimension" /> //右下角的圆角半径
- android:type=["linear" | "radial" | "sweep"] //共有3中渐变类型,线性渐变(默认)/放射渐变/扫描式渐变
- android:angle="integer" //渐变角度,必须为45的倍数,0为从左到右,90为从上到下
- android:centerX="float" //渐变中心X的相当位置,范围为0~1
- android:centerY="float" //渐变中心Y的相当位置,范围为0~1
- android:startColor="color" //渐变开始点的颜色
- android:centerColor="color" //渐变中间点的颜色,在开始与结束点之间
- android:endColor="color" //渐变结束点的颜色
- android:gradientRadius="float" //渐变的半径,只有当渐变类型为radial时才能使用
- android:useLevel=["true" | "false"] /> //使用LevelListDrawable时就要设置为true。设为false时才有渐变效果
- <stroke
- android:width="dimension" //描边的宽度
- android:color="color" //描边的颜色
- // 以下两个属性设置虚线
- android:dashWidth="dimension" //虚线的宽度,值为0时是实线
- android:dashGap="dimension" /> //虚线的间隔
- android:shape=["rectangle" | "oval" | "line" | "ring"]
- shape的形状,默认为矩形,可以设置为矩形(rectangle)、椭圆形(oval)、线性形状(line)、环形(ring)
- 下面的属性只有在android:shape="ring时可用:
- android:innerRadius 尺寸,内环的半径。
- android:innerRadiusRatio 浮点型,以环的宽度比率来表示内环的半径,
- android:thickness 尺寸,环的厚度
- android:thicknessRatio 浮点型,以环的宽度比率来表示环的厚度,例如,如果android:thicknessRatio="2",
- android:useLevel boolean值,如果当做是LevelListDrawable使用时值为true,否则为false.
2.上面那个略有瑕疵 比如老夫就是喜欢用BaseRecyclerViewAdapter
看似寻常,实则叼的一批.