Highlight on clickablespan click
I've got little problem, i need to remove or customize this orange highlight during clicking on clickablespan. This is my class extending ClickableSpan
public class InternalClickableSpan extends ClickableSpan {
private String clicked;
@Override
public void updateDrawState(TextPaint ds) {
ds.setUnderlineText(false);
}
public InternalClickableSpan(String clickedString) {
clicked = clickedString;
}
@Override
public void onClick(View view) {
Selection.setSelection((Spannable) ((TextView)view).getText(), 0);
Toast toast = Toast.makeText(mContext, clicked, Toast.LENGTH_SHORT);
toast.show();
}
}
and this is how i use it on text view
Spannable spans = (Spannable) tv.getText();
spans.setSpan(new InternalClickableSpan(contacts[i]), text.indexOf(contacts[i]), text.indexOf(contacts[i])+contacts[i].length(), Spa开发者_如何学编程nnable.SPAN_EXCLUSIVE_EXCLUSIVE);
Does anybody know how to customize "onclick highlight" on spannable object?
edit: Thanks Aleadam for response, i'am overriding updateDrawState (please take a look at the first method in my InternalClickableSpan class), but i can't find a way to customize this higlight anyway. Has anybody got other ideas? Thanks
You can override onClick(View widget)
like this:
@Override
public void onClick(View widget) {
// do what must happen after click event.
widget.invalidate();
}
This will remove any highlight.
tv.setHighlightColor(Color.TRANSPARENT);
ClickableSpan linkClick = new ClickableSpan() {
@Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "Link Click",
Toast.LENGTH_SHORT).show();
view.invalidate();
}
@Override
public void updateDrawState(TextPaint ds) {
if (textView.isPressed()) {
ds.setColor(Color.BLUE);
} else {
ds.setColor(Color.RED);
}
textView.invalidate();
}
};
textView.setHighlightColor(Color.TRANSPARENT);
Spannable spannableString = new SpannableString("Link in TextView");
spannableString.setSpan(linkClick, 0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(spannableString, TextView.BufferType.SPANNABLE);
textView.setMovementMethod(LinkMovementMethod.getInstance());
just use this..
view.setSelector(new ColorDrawable(Color.TRANSPARENT));
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:id="@+id/LinearLayout02"
android:layout_height="50px"
android:layout_width="fill_parent"
// Layout Click enable
android:clickable="true"
// Setting Highlight Option in background property
android:background="@android:drawable/list_selector_background" />
</LinearLayout>
</LinearLayout>
u can replace default highlightColor android:textColorHighlight
<TextView
android:id="@+id/tv_tip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#727998"
android:textColorHighlight="@android:color/transparent"
tools:text="@string/_tip" />
or disable focus
textView.setText(myString);
Linkify.addLinks(textView,Linkify.ALL);
This works for me.
精彩评论