[英]Using TextView as link for android app?
在我的Android应用程序中,我有一个textview,我将它用作打开网站的链接。 但是,当单击textView
时, alert pops up
,浏览器没有响应。
<string name="MoneyControl"><a href="http://www.moneycontrol.com/stocksmarketsindia/"> 1. Money Control</a></string>
<TextView
android:id="@+id/moneycontrol"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/MoneyControl"
android:textSize="15dp" />
link = (TextView) findViewById(R.id.moneycontrol);
if (link !=null){
link.setMovementMethod(LinkMovementMethod.getInstance());
}
您可以使用此解决方案来做到这一点:
SpannableString ss = new SpannableString("Your text here");
ss.setSpan(new StyleSpan(Typeface.NORMAL), 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ForegroundColorSpan fcs = new ForegroundColorSpan(Color.BLUE);
ss.setSpan(fcs, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new UnderlineSpan(), 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
yourTextView.setText(ss);
yourTextView.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
String _url = "Your link here";
Intent webIntent = new Intent(Intent.ACTION_VIEW);
webIntent.setData(Uri.parse(_url));
startActivity(webIntent);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.