我在 Android 布局中显示一个链接,如下所示:
<TextView
android:id="@+id/linkable_text”
android:layout_width="match_parent"
android:layout_height="match_parent"
android:autoLink="web"
/>
我也这样做:text.setMovementMethod(LinkMovementMethod.getInstance());
这可行,但我想导航到与 TextView 中显示的 URL 不同的 URL(我动态添加它)。
我的意思是用户界面中的链接显示:file.html
,但是当我按下该链接时,我想导航到如下网址:http://IP/path/file.html
我怎样才能做到这一点,而不必在我的 TextView 中显示整个 URL
最佳答案
Try this, and let me know what happen..
TextView textView =(TextView)findViewById(R.id.textView);
textView.setClickable(true);
textView.setMovementMethod(LinkMovementMethod.getInstance());
String text = "<a href='http://www.google.com'> Google </a>";
textView.setText(Html.fromHtml(text));
关于java - 相当于android中的html img src,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29411466/