2016-01-25 28 views
-1

我想爲TextView定義autolink =「web」。令人驚訝的是,當我聲明這一點時,TextView中的文本被隱藏起來,只有在第一次點擊時才能看到。這是如此令人驚訝我在我的應用程序的許多部分中都有相同的功能,可以正常工作。這是我找不到問題的唯一地方。在TextView中聲明自動鏈接隱藏文本...!

請幫我一個解決方案:

這裏是我的TextView XML代碼:

<TextView 
      android:id="@+id/details_webAddress_textView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/details_location_textView" 
      android:drawableLeft="@drawable/icon_website_earth" 
      android:drawablePadding="5dp" 
      android:gravity="center" 
      android:padding="5dp" 
      android:singleLine="true" 
      android:autoLink="web" 
      android:text="www.google.com" 
      android:visibility="visible" /> 

以下是TextView的地方自動鏈接運行良好:

<TextView 
       android:id="@+id/websiteAddress_textView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:autoLink="web" 
       android:padding="5dp" 
       android:singleLine="true" 
       android:text="www.stackoverflow.com" /> 
+0

......也許你應該在應用程序的其他部分也發佈這個完全相同的東西的部分的代碼段? – Shark

回答

2

嘗試使用:

TextView textLink = (TextView) findViewById(R.id.details_webAddress_textView); 
textLink.setVisibility(View.INVISIBLE); 
Button buttonDetails = (Button) findViewById(R.id.button); 

buttonDetails.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       textLink.setVisibility(View.VISIBLE); // text visible on firt click 
       String url = "http://www.example.com"; 
       Intent i = new Intent(Intent.ACTION_VIEW); 
       i.setData(Uri.parse(url)); 
       startActivity(i); // open link with default browser 
      } 
     }); 
0

Tou需要在xml中爲「android:autoLink」屬性另外設置「android:textColorLink」屬性。

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:autoLink="web" 
    android:textColorLink="@color/yourDesiredLinkColor"/>