TextView based on iconfont extension (support left and right Text setting, Shape setting, span setting, etc.)
Project introduction
- Still suffering from iconfont left and right sides also need to set up text can only add two TextView?
- Are you still suffering from the need to set up all kinds of similar borders and new Shape files?
- Still suffering from setting click effects and multiple styles?
- Still suffering from using Linear Layout to wrap one layer? (Code cleanliness patients ~). A lightweight TextView based on iconfont extension supports multiple functions, reducing layout nesting and defining shape files. It basically covers functions that require multiple TextViews in general.
Supported features
- Easy to use
- call chaining
- Support for setting text around iconfont
- Supporting all properties of common shape s directly set in xml
- Support for setting iconfont, left text, right text color (Selector can also be)
- Support the setting of iconfont, left text and right text fonts respectively
- Support text and iconfont centering
- Support multiple span s for left and right text settings
- padding for setting iconfont and left and right text
- Rich api s, all properties support xml and java calls
Source address
Welcome to Ti issues and PR
Download
Step1
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step2
Step 2. Add the dependency
dependencies {
implementation 'com.github.DrownCoder:EasyTextView:v1.0'
}
Effect
Use
xml attribute
<com.study.xuan.library.widget.EasyTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#494949"
android:textSize="14dp"
app:iconColor="@android:color/holo_red_light"
app:strokeColor="@android:color/holo_red_light"
app:strokeWidth="1dp"
app:textPadding="5dp"
app:textRight="follow"
app:totalRadius="12dp" />
<declare-styleable name="EasyTextView">
//Type: RECTANGLE: 0 (default), OVAL (1), LINE (2) in Shape
<attr name="shapeType" format="integer" />
//Rounded corners of four corners
<attr name="totalRadius" format="dimension"/>
//Top left corner
<attr name="radiusTopLeft" format="dimension"/>
//Lower left quarter
<attr name="radiusBottomLeft" format="dimension"/>
//Upper right corner
<attr name="radiusTopRight" format="dimension"/>
//Lower right corner
<attr name="radiusBottomRight" format="dimension"/>
//Colour of Side Line
<attr name="strokeColor" format="color"/>
//Width of Side Line
<attr name="strokeWidth" format="dimension" />
//Filled color
<attr name="soildBac" format="color"/>
//The iconfont distance in the middle is about the inner margin of the Text
<attr name="textPadding" format="dimension"/>
//The text on the left
<attr name="textLeft" format="string"/>
//The text on the right
<attr name="textRight" format="string"/>
//The color of iconfont in the middle (note that the TextColor attribute overrides)
<attr name="iconColor" format="reference|color"/>
//The color of the text on the left (note that the TextColor attribute overrides)
<attr name="textLeftColor" format="reference|color"/>
//The color of the right text (note that the TextColor attribute overrides)
<attr name="textRightColor" format="reference|color"/>
//Left text size (iconfont size is TextSize, not overwritten)
<attr name="textLeftSize" format="dimension"/>
//The size of the text on the right (iconfont size is TextSize, not overwritten)
<attr name="textRightSize" format="dimension"/>
</declare-styleable>
java Api
//Few attributes can be set directly
etvGet.setTextRight(Pay close attention to);
//Multiple attributes can be called in chains to reduce redundancy, save performance, and pay attention to the final build()
etvGet.strokeWidth(DensityUtils.dp2px(context, 1))
.strokeColor(Color.parseColor("#ffe849"))
.solid(Color.parseColor("#e8264a"))
.icon(context.getText(R.string.icon_font_check).toString())
.textRight("follow").build();
/**
* Non-chain call api
*/
public void setType(int type);
public void setStrokeWidth(int value);
public void setStrokeColor(@ColorInt int color);
public void setSolid(int soild);
public void setIconColor(int color);
public void setTextLeft(CharSequence textLeft);
public void setTextRight(CharSequence textRight);
public void setTextLeftColor(int color);
public void setTextRightColor(int color);
public void setTextLeftSize(float leftSize);
public void setTextRightSize(float rightSize);
public void setIcon(String iconText);
public void clearSpan();
public void addSpanLeft(Object object, int start, int end, int flags);
public void addSpanLeft(List<Object> objects, int start, int end, int flags);
public void addSpanRight(List<Object> objects, int start, int end, int flags);
public void addSpanRight(Object object, int start, int end, int flags);
More
Setting Shape dynamically by SupperShape Implemented, you can dynamically set Shape for any View through java code, no need to write shape.xml file, welcome to use.
This project is only based on TextView for encapsulation, other Views can be encapsulated according to requirements, the principle is relatively simple, you can View the source code.
Detailed instructions for reference Wiki