gpt4 book ai didi

android - TextView 链接在我的模拟器 fragment 中不起作用

转载 作者:行者123 更新时间:2023-11-29 23:30:58 25 4
gpt4 key购买 nike

我想在我的 TextView 中放置一个 Web 链接。我在 fragment 中使用 TextView。我认为它不适用于模拟器。我换了模拟器,还是有同样的问题。

以下是我尝试过的解决方案:

  1. How to open URL from Fragment TextView?
  2. Android - Hyperlink is not clickable
  3. Why link does not work in the text view?

我的 TextViewlinearLayout

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

最佳答案

也许这对你有帮助:

    SpannableString string = new SpannableString("Privacy Policy");
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View textView) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://csunix.mohawkcollege.ca/~000762465/Privacy%20Policy/ielts_up.html"));
startActivity(browserIntent);
}
};
string.setSpan(clickableSpan, 0, string.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

TextView textView = (TextView) findViewById(R.id.text);
textView.setText(string);
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setHighlightColor(Color.TRANSPARENT);

关于android - TextView 链接在我的模拟器 fragment 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52674212/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com