我的应用从在线服务器检索数据。如果我在应用程序中插入像Hello这样的服务器,如果你点击上面的任何地方都没有。为什么?这是来源
MyText = (TextView) this.findViewById(R.art.tit);
Text = (TextView) this.findViewById(R.artic.text);
String formattedText = db.getTesto();
String formattedTitle = db.getTitolo();
MyText.setText(Html.fromHtml(formattedTitle));
Text.setText(Html.fromHtml(formattedText));
答案 0 :(得分:0)
这是超链接的示例:
MyText = (TextView) this.findViewById(R.art.tit);
Text = (TextView) this.findViewById(R.artic.text);
tv1.setLayoutParams(textOutLayoutParams);
tv1.setText(Html.fromHtml("<a href=\""+ formattedText + "\">" + formattedTitle + "</a>"));
tv1.setClickable(true);
tv1.setMovementMethod (LinkMovementMethod.getInstance());
dialogLayout.addView(tv1);
答案 1 :(得分:0)
我终于使用以下代码了解它:
TextView tv1 = new TextView(this);
tv1.setLayoutParams(textOutLayoutParams);
tv1.setText(Html.fromHtml("<a href=\""+ l.getRightString() + "\">" + l.getLeftString() + "</a>"));
tv1.setClickable(true);
tv1.setMovementMethod (LinkMovementMethod.getInstance());
dialogLayout.addView(tv1);
l.getRightString()
- 包含以下网址:http:\www.google.com
l.getLeftString()
- 包含网址文字,如:"Go to Google"
结果:文字&#34;转到Google&#34;在我的蓝色和带下划线的对话框上,点击它时,浏览器打开并显示相应的页面。
返回/退出浏览器时,它再次从应用程序离开的状态进入应用程序。
希望这有帮助。
答案 2 :(得分:0)
在android中你可以用两种方式添加链接,
- 在用于textview的XML设计android:autoLink="web"
中,它将带您进入Web浏览器
- 如果要添加代码,可以添加
TextView yourTextview= (TextView) findViewById(R.id.noteview);
yourTextview.setText(youURL link);
Linkify.addLinks(yourTextview, Linkify.ALL);
感谢。