选择超链接的TextView [英] Selector to Hyperlink TextView
本文介绍了选择超链接的TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个的TextView
的点击触发浏览器打开一个url.How来选择适用于的TextView
。我试图的android:文字颜色=@绘制/ text_selector
这是工作的所有其他 TextViews
I have a TextView
whose click triggers the browser to open a url.How to apply selector to the TextView
. I tried android:textColor="@drawable/text_selector"
which is working for all other TextViews
.
<TextView
android:id="@+id/txtWebsite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:linksClickable="true"
android:textColor="@drawable/text_selector"
android:textSize="@dimen/web_textsize"
android:textStyle="normal" />
我试过的android:textColorLink =@绘制/ text_selector
也未工作或者
推荐答案
我用我的方式实现,它的正常工作。
Workaround:
I implemented by my way and it's working fine.
textview=(TextView) findViewById(R.id.textview);
textview.setClickable(true);
String mystring=new String("https://www.google.com");
SpannableString content = new SpannableString(mystring);
content.setSpan(new UnderlineSpan(), 0, mystring.length(), 0);
textview.setText(content);
textview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
和 XML的TextView
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_centerInParent="true"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="http://www.google.com"
android:textColor="@color/text_selector"
android:textSize="18sp"
android:textStyle="bold" />
和 RES /彩色/ selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#7fa87f" android:state_pressed="true" />
<!-- pressed -->
<item android:color="#ff33b5" android:state_focused="true" />
<!-- focused -->
<item android:color="#061476" />
<!-- default -->
</selector>
输出:具有哈弗
这篇关于选择超链接的TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文