为Android TextView增加高度可定制多彩的链接:LinkTextView
jopen
10年前
LinkTextView是一个为Android TextView增加高度可定制多彩链接的库。
特性
- 易于增加链接和附加数据
- 设置链接的正常颜色和点过的颜色。
- 设置背景正常颜色,和点过的颜色。
示例
See the LinkTextViewSample for a common use of this library.
如何使用:
Download the LinkTextView.java file and copy it into your project.
Add LinkTextView to your layout.
<com.zekunyan.linktextview.LinkTextView android:id="@+id/linkTextView" android:layout_width="match_parent" android:layout_height="80dp" android:background="#DDDDDD" android:gravity="center" android:textColor="#000000" android:textSize="24sp" />
Get the instance of LinkTextView.
linkTextView = (LinkTextView) findViewById(R.id.linkTextView);
Set text.
linkTextView.setClickableText("Example link.");
Add link with default color.
int linkID = linkTextView.addClick( linkBegin, //Link begin linkEnd, //Link end new LinkTextView.OnClickInLinkText() { @Override public void onLinkTextClick(String clickText, int linkID, Object attachment) { Log.i(LOG_TAG, "You click manual link. It's attachment is: " + attachment); } }, "This is attachment." //Link attachment );
Or add link with custom color.
int linkID = linkTextView.addClick( linkBegin, //Link begin linkEnd, //Link end new LinkTextView.OnClickInLinkText() { @Override public void onLinkTextClick(String clickText, int linkID, Object attachment) { Log.i(LOG_TAG, "You click example link. It's attachment is: " + attachment); } }, "This is example link attachment", //Link attachment true, //Show link underline Color.BLACK, //Text normal color Color.YELLOW, //Text pressed color Color.WHITE, //Background normal color Color.GREEN //Background pressed color );
You can change specific Link's color by its ID.
linkTextView.setTextPressedColor(linkID, Color.RED);
You can remove specific link by its ID.
linkTextView.removeLink(linkID);