2013-07-19 94 views
1

如何在點擊打開谷歌主頁上的android超鏈接文本視圖正在嘗試與它只是改變普通的文本,超鏈接下面的代碼,但是,點擊如何解決它如何在android中點擊文本視圖超鏈接打開Goog​​le頁面?

這裏是代碼:

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

的strings.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" /> 
+0

你想讓它在瀏覽器中打開嗎? –

+0

http://stackoverflow.com/questions/7570239/android-linkify-text-spannable-text-in-single-text-view-as-like-twitter-twee。搜索,所以你會有很多類似的帖子 – Raghunandan

+0

你想在你的應用中嵌入一個網頁瀏覽器,或者在你的設備上啓動默認瀏覽器。每個所需的代碼明顯不同 –

回答

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" /> 
+0

中啓動默認瀏覽器,它不適合我 –

相關問題