ClickableSpan的TextView保持点击后选择 [英] ClickableSpan TextView stays selected after click
本文介绍了ClickableSpan的TextView保持点击后选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用下面的code,使我的的TextView
看起来像一个链接,当用户点击了它我表现出 AlertDialog
。但文本选择保持用户离开该对话框,它看起来丑陋了。
I'm using the following code to make my TextView
appear like a link, and when user clicks on it I show an AlertDialog
. But the text stays selected after user leaves the dialog and it looks ugly.
TextView terms = (TextView)findViewById(R.id.TextViewTerms);
terms.setMovementMethod(LinkMovementMethod.getInstance());
Spannable spanTerms = (Spannable)terms.getText();
ClickableSpan clickSpan = new ClickableSpan()
{
@Override
public void onClick(final View view)
{
new AlertDialog.Builder(AboutActivity.this)
.setTitle(R.string.title_terms)
.setMessage(R.string.terms_of_use)
.setCancelable(true)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
}
})
.show();
}
};
spanTerms.setSpan(clickSpan, 0, spanTerms.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
我也打过电话的setSelected(假)
但这并不能工作。任何想法?
I've also tried calling setSelected(false)
but that doesn't work either. Any ideas?
推荐答案
只需添加 Selection.setSelection(spanTerms,0);
里面的的onClick
你的对话框的方法。
Just add Selection.setSelection(spanTerms, 0);
inside your onClick
method of your dialog.
这篇关于ClickableSpan的TextView保持点击后选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文