2014-03-12 32 views
0

在我的android应用程序中,我有一个textview,我使用它作为打开网站的链接。但是当点击textView a alert pops up浏览器没有响应。使用TextView作为Android应用程序的链接?

<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()); 
    } 
+0

尝试设置这样'机器人:自动链接= “网络”''机器人:linksClickable = “真”'你'TextView'和删除'link.setMovementMethod(LinkMovementMethod.getInstance());' –

+0

试试这个http://stackoverflow.com/a/11259909/1012284 –

+0

@简单的计划对我来说不起作用。 –

回答

0

您可以使用此解决方案做到这一点:

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); 
    } 

}); 
相关问题