0

For some reason after I made textviews clickable and have autolink set to web it still doesn't open a browser. Do I need to use an event listener then handle it that way? Or is it something simple that I am overlooking? I'll start by posting the textview XML code :

    <TextView
        android:id="@+id/textView6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.11"
        android:autoLink="web"
        android:background="@drawable/back"
        android:clickable="true"
        android:gravity="center"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />
4

3 回答 3

1

这段代码是大约一年前写的,但我认为它应该可以工作:

TextView result_view = new TextView(this);
result_view.setText(Html.fromHtml("<a href=" + linkUrl + ">"+ linkTitle + "</a>"));
result_view.setMovementMethod(LinkMovementMethod.getInstance());
于 2013-06-04T19:52:01.967 回答
0

添加以下行。

final TextView input = new TextView(this);
            alert.setView(input);
            input.setText(Html.fromHtml("www.google.com")); // you can pass your strings over there. 
            Linkify.addLinks(input, Linkify.ALL); 
            alert.setMessage("Test");

希望这对您有所帮助。

于 2013-06-05T12:59:15.717 回答
0

我不得不使用 onclick 事件来处理浏览器的启动。我仍然是 android 编程的业余爱好者,所以我从这里得到了信息:

// Register an onClickListener
            Intent broswerIntent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://www.cnn.com"));
            broswerIntent.addCategory(Intent.CATEGORY_BROWSABLE);
            broswerIntent.setComponent(new ComponentName("com.android.browser",

            "com.android.browser.BrowserActivity"));
            PendingIntent pendingIntent = PendingIntent.getActivity(
                    getApplicationContext(), 0, broswerIntent, 0);
于 2013-06-05T12:51:53.543 回答