1

AndroidでハイパーリンクテキストビューをクリックしてGoogleホームページを開く方法は、次のコードで試していますが、ハイパーリンクをクリックすると、通常のテキストに変更されるだけです。それを解決する方法

コードは次のとおりです。

MainActivity.java ( onCreate() 内)

instruction = (TextView) findViewById(R.id.example);

    instruction.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            instruction.setText(Html.fromHtml(getString(R.string.Google_Instructions)));
            Linkify.addLinks(instruction, Linkify.ALL);
            instruction.setMovementMethod(LinkMovementMethod.getInstance());                
        }
    });

文字列.xml

<string name="Google_Instructions">opens <a href="https://www.google.co.in">Google</a> page </string>

layout_test.xml

 <TextView
        android:id="@+id/example"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10sp"
        android:clickable="true"
        android:text="@string/Google_Instructions"
        android:autoLink="web"
        android:textSize="16sp" />
4

1 に答える 1

1

こんにちは、この小さなコードをJavaクラスに追加し、レイアウトxmlファイルを少し変更することで解決策を得ました

instruction = (TextView) findViewById(R.id.example);

    instruction.setText(Html
            .fromHtml("<b> To open google console </b> "
                    + "<a href=\"https://code.google.com/apis/console\">Click here</a> "));
    instruction.setMovementMethod(LinkMovementMethod.getInstance());

layout_test.xml

 <TextView
        android:id="@+id/example"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
于 2013-07-23T09:58:26.650 に答える