Skip to content

Repository files navigation

AutoSpannableTextView

Support some of the key words can be clicked with the underline TextView

Step1:

 <declare-styleablename="AutoLinkStyleTextView">
<attrname="AutoLinkStyleTextView_text_value"format="string|reference"/>//key word with color and underline, and split with ','(en)
<attrname="AutoLinkStyleTextView_default_color"format="color|reference"/>//word and underline's color
<attrname="AutoLinkStyleTextView_has_under_line"format="boolean"/>//underline with true and false
<attrname="AutoLinkStyleTextView_start_image"format="reference"/>//start with image 's TextView
<attrname="AutoLinkStyleTextView_type">
<enumname="start_image"value="0"/>
<enumname="content_text"value="1"/>//default
</attr>
</declare-styleable>

Step2:

 //style1
<xx.AutoLinkStyleTextView
android:id="@+id/tv_clause"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="我已核对付款金额,仔细阅读并同意“购买须知”及约克论坛团购“用户条款”"android:textSize="16sp"app:AutoLinkStyleTextView_text_value="“购买须知”,“用户条款”"
/>
//style2
<xx.AutoLinkStyleTextView
android:id="@+id/tv_start_image"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="活动介绍,开始以图片开头"android:textSize="16sp"app:AutoLinkStyleTextView_start_image="@mipmap/ic_qupai_subject_information"app:AutoLinkStyleTextView_type="start_image"
/>

Step3:

//style1autoLinkStyleTextView.setOnClickCallBack(newAutoLinkStyleTextView.ClickCallBack() {
@OverridepublicvoidonClick(intposition) {
if (position == 0) {
Toast.makeText(MainActivity.this, "购买须知", Toast.LENGTH_SHORT).show();
} elseif (position == 1) {
Toast.makeText(MainActivity.this, "用户条款", Toast.LENGTH_SHORT).show();
}
}
});
//style2setStartImageText(tvStartImage.getText());

About

Support some of the key words can be clicked with the underline TextView

Resources

Stars

361 stars

Watchers

6 watching

Forks

Releases

Packages

Contributors

Languages