【发布时间】:2018-10-05 22:55:38
【问题描述】:
我想在我的TextView 中添加一个网络链接。我在我的片段中使用TextView。我认为它不适用于模拟器。换了模拟器还是一样的问题。
以下是我尝试过的解决方案:
- How to open URL from Fragment TextView?
- Android - Hyperlink is not clickable
- Why link does not work in the text view?
我的TextView在linearLayout里面
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/privacy_policy"
android:textColor="@color/colorPrimary"
android:padding="10dp"
android:textSize="17sp"
android:textStyle="bold"
android:autoLink="all"
android:clickable="true"
android:focusable="true"
android:linksClickable="true"
android:id="@+id/tv_privacy_policy" />
我的字符串值
<string name="privacy_policy">Privacy Policy<a href="https://csunix.mohawkcollege.ca/~000762465/Privacy%20Policy/ielts_up.html"></a></string>
我的onCreateView()
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_aboutus, container, false);
TextView tv_privacy_policy = (TextView)rootView.findViewById(R.id.tv_privacy_policy);
// Linkify.addLinks(tv_privacy_policy, Linkify.WEB_URLS);
// Inflate the layout for this fragment
tv_privacy_policy.setMovementMethod(LinkMovementMethod.getInstance());
String text = "<a href='http://www.google.com'>Pricacy Policy</a>";
tv_privacy_policy.setText(Html.fromHtml(text));
return rootView;
}
【问题讨论】: