Jak zrobić linki w widoku tekstowym klikalne?

Zdefiniowałem następujący TextView:

<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:text="@string/txtCredits"
    android:autoLink="web" android:id="@+id/infoTxtCredits"
    android:layout_centerInParent="true"
    android:linksClickable="true"></TextView>

Gdzie @string/txtCredits jest zasobem łańcuchowym zawierającym <a href="some site">Link text</a>.

Android podświetla linki w widoku tekstowym, ale nie reagują na kliknięcia. Czy ktoś może mi powiedzieć, co robię źle? Czy muszę ustawić onClickListener dla TextView w mojej aktywności dla czegoś tak prostego jak to?

Wygląda na to, że ma to związek ze sposobem, w jaki definiuję mój zasób ciągów. To nie działa:

<string name="txtCredits"><a href="http://www.google.com">Google</a></string>

Ale tak:

<string name="txtCredits">www.google.com</string>

Co jest przykre, ponieważ wolałbym pokazać link tekstowy niż pokazać pełny adres URL.

Author: Samet ÖZTOPRAK, 2010-04-29

30 answers

Zakopany w demach API znalazłem rozwiązanie mojego problemu:

Link.java:

    // text2 has links specified by putting <a> tags in the string
    // resource.  By default these links will appear but not
    // respond to user input.  To make them active, you need to
    // call setMovementMethod() on the TextView object.

    TextView t2 = (TextView) findViewById(R.id.text2);
    t2.setMovementMethod(LinkMovementMethod.getInstance());

Usunąłem większość atrybutów na moim TextView, aby pasowały do tego, co było w demo.

<TextView
    android:id="@+id/text2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/txtCredits"/>
To rozwiązało problem. Dość trudne do odkrycia i naprawienia.

Ważne : nie zapomnij usunąć autoLink="web", jeśli wywołujesz setMovementMethod().

 1270
Author: Richard,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-07-26 11:59:11

Używam tylko {[0] } i działa dobrze. Kliknięcie na link otwiera przeglądarkę i pokazuje poprawną stronę.

Mogę się domyślić, że nad linkiem znajduje się inny widok. Coś, co jest przezroczyste, wypełnia cały rodzic, ale nie wyświetla niczego powyżej łącza. W takim przypadku kliknięcie przechodzi do tego widoku zamiast linku.

 552
Author: Janusz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-04-29 07:13:43

Po spędzeniu trochę czasu z tym, odkryłem, że:

  • android:autoLink="web" działa, jeśli masz pełne linki w HTML. Następujące elementy będą podświetlone na niebiesko i klikalne:
  • jakiś tekst <a href="http://www.google.com">http://www.google.com</a>
  • jakiś tekst http://www.google.com
  • view.setMovementMethod(LinkMovementMethod.getInstance()); będzie działać z następującymi (będą podświetlane i klikalne):
  • jakiś tekst <a href="http://www.google.com">http://www.google.com</a>
  • jakiś tekst http://www.google.com
  • jakiś tekst <a href="http://www.google.com">Go to Google</a>

Zauważ, że trzecia opcja zawiera hiperłącze, ale opis odnośnika (części między znacznikami) nie jest odnośnikiem. android:autoLink="web" czy Nie Działa z takimi linkami.

  • android:autoLink="web" jeśli ustawione w XML nadpisze view.setMovementMethod(LinkMovementMethod.getInstance()); (tzn. linki trzeciego rodzaju zostaną podświetlone, ale nie będą klikalne).

Morał tej historii to użycie view.setMovementMethod(LinkMovementMethod.getInstance()); w kodzie i upewnienie się, że nie masz android:autoLink="web" w układzie XML, jeśli chcesz wszystkich linki do klikania.

 406
Author: Jeshurun,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-12-10 14:03:37

Powyższe rozwiązania nie działały dla mnie, ale poniższe (i wydaje się nieco czystsze).
Najpierw w zasobie string zdefiniuj swój znacznik otwierający za pomocą kodowania encji HTML, np.:

&lt;a href="http://www.google.com">Google&lt;/a>

A NIE:

<a href="http://www.google.com">Google</a>

Ogólnie, Zakoduj wszystkie szewrony w sznurku w ten sposób. BTW, link musi zaczynać się od http://

Następnie (zgodnie z sugestią tutaj) ustaw tę opcję w widoku tekstu:

 android:linksClickable="true"

Wreszcie, w kodzie, do:

((TextView) findViewById(R.id.your_text_view)).setMovementMethod(LinkMovementMethod.getInstance());
((TextView) findViewById(R.id.your_text_view)).setText(Html.fromHtml(getResources().getString(R.string.string_with_links)));

To jest to, nie są wymagane wyrażenia regularne ani inne hacki ręczne.

 98
Author: Błażej Czapp,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 11:47:32

Użyłem tego po prostu

Linkify.addLinks(TextView, Linkify.ALL);

Sprawia, że linki klikalne podane tutaj

 74
Author: jai_b,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-03-26 13:00:01

Jeśli chcesz dodać link podobny do HTML, wystarczy:

  • Dodaj łańcuch HTML podobny do zasobu:

     <string name="link"><a href="https://www.google.pl/">Google</a></string>
    
  • Dodaj swój widok do układu bez konfiguracji specyficznej dla linku:

     <TextView
        android:id="@+id/link"
        android:text="@string/link" />`
    
  • Dodaj odpowiednie MovementMethod programowo do widoku tekstu:

     mLink = (TextView) findViewById(R.id.link);
     if (mLink != null) {
       mLink.setMovementMethod(LinkMovementMethod.getInstance());
     }
    
To jest to! I tak, posiadanie opcji takich jak" autoLink " i "linksClickable" działających tylko na jawnych linkach (nie zawiniętych w znaczniki html) jest bardzo mylące dla mnie też...
 72
Author: vizZ,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-07-08 13:47:15

Dodałem ten wiersz do TextView: android:autoLink="web"
Poniżej znajduje się przykład użycia w pliku układu.

layout.xml próbka

    <TextView
        android:id="@+id/txtLostpassword"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:autoLink="email"
        android:gravity="center"
        android:padding="20px"
        android:text="@string/lostpassword"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/txtDefaultpassword"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:autoLink="web"
        android:gravity="center"
        android:padding="20px"
        android:text="@string/defaultpassword"
        android:textAppearance="?android:attr/textAppearanceSmall" />

string.xml

<string name="lostpassword">If you lost your password please contact <a href="mailto:[email protected]?Subject=Lost%20Password" target="_top">[email protected]</a></string>

<string name="defaultpassword">User Guide <a href="http://www.cleverfinger.com.au/user-guide/">http://www.cleverfinger.com.au/user-guide/</a></string>
 49
Author: Shanewaj,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-09-20 18:20:45

Poniższy tekst powinien działać dla każdego, kto szuka kombinacji tekstu i hiperłącza w aplikacji na Androida.

W string.xml:

<string name="applink">Looking for Digital Visiting card? 
<a href="https://play.google.com/store/apps/details?id=com.themarkwebs.govcard">Get it here</a>
</string>

Teraz możesz użyć tego string w dowolnym View w następujący sposób:

<TextView
    android:id="@+id/getapp"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:gravity="center"
    android:textColor="@color/main_color_grey_600"
    android:textSize="15sp"
    android:text="@string/applink"/>

Teraz, w swojej aktywności lub fragmencie, wykonaj następujące czynności:

TextView getapp =(TextView) findViewById(R.id.getapp);
getapp.setMovementMethod(LinkMovementMethod.getInstance());

Do tej pory nie musisz ustawiać android:autoLink="web" lub android:linksClickable="true" za pomocą tego podejścia.

Mam nadzieję, że okaże się to pomocne.

 48
Author: Asesha George,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-03-27 12:55:49

Mam nadzieję, że to ci pomoże;

String value = "<html>Visit my blog <a href=\"http://www.maxartists.com\">mysite</a> View <a href=\"sherif-activity://myactivity?author=sherif&nick=king\">myactivity</a> callback</html>";
    TextView text = (TextView) findViewById(R.id.text);


    text.setText(Html.fromHtml(value));
    text.setMovementMethod(LinkMovementMethod.getInstance());
 29
Author: Bebin T.N,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-06-18 06:14:00

Najprostszą rzeczą, która mi pomogła, jest użycie Linkify

TextView txt_Message = (TextView) view.findViewById(R.id.txt_message);
txt_Message.setText("This is link https://www.google.co.in/");
Linkify.addLinks(txt_Message, Linkify.WEB_URLS);

I automatycznie wykryje adresy URL z tekstu w widoku tekstowym.

 27
Author: Pravesh,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-07-29 14:05:14

Tylko co trzeba dodać w widoku tekstowym w xml

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:autoLink="web"/>
 26
Author: Ahmed Mostafa,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-01-29 02:39:26

Richard, następnym razem powinieneś dodać ten kod pod TextView w layout XML.

android:autoLink="all"
Tak powinno być.
<TextView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:text="@string/txtCredits"
    android:id="@+id/infoTxtCredits"
    android:autoLink="all"
    android:linksClickable="true">
</TextView>

Nie musisz używać tego kodu (t2.setMovementMethod(LinkMovementMethod.getInstance());), aby link był klikalny.

Prawda jest taka: dopóki ustawisz autoLink i linksClickable , nie zapomnij dodać tego w String.plik xml , aby klikalny link działał.

<string name="txtCredits"><a href="http://www.google.com">Google</a></string>
 20
Author: David Dimalanta,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-07-09 20:52:04

Za pomocą linkify : Linkify pobiera fragment tekstu i wyrażenie regularne i zamienia wszystkie dopasowania regex w tekście w klikalne linki

TextView textView = (TextView) findViewById(R.id.textView);
textView.setText("http://www.domain.com");
Linkify.addLinks(textView, Linkify.WEB_URLS);

Nie zapomnij

import android.widget.TextView;
 19
Author: DeathRs,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-02-07 20:15:43

Zarządzaj również kolorem tekstu Linkify Tutaj wpisz opis obrazka

tv_customer_care_no.setLinkTextColor(getResources().getColor(R.color.blue));
  tv_customer_care_no.setText("For us to reach out to you, please fill the details below or contact our customer care at  18004190899 or visit our website http://www.dupont.co.in/corporate-links/contact-dupont.html ");
   Linkify.addLinks(tv_customer_care_no, Linkify.WEB_URLS | Linkify.PHONE_NUMBERS);
   Linkify.addLinks(tv_customer_care_no, Linkify.ALL );
 19
Author: Keshav Gera,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-06-30 05:41:15

Oto bardzo jeden wiersz kodu Androida, aby telefon i adres URL można było wybrać z textView bez względu na to, co jest ciągiem znaków, a co danymi. Nie musisz używać do tego żadnych znaczników HTML.

TextView textView = (TextView)findViewById(R.id.textView1);
textView.setText("some url is www.google.com phone 7504567890 another url lkgndflg.com ");

// Makes the textView's Phone and URL (hyperlink) select and go.
Linkify.addLinks(textView, Linkify.WEB_URLS | Linkify.PHONE_NUMBERS);
 18
Author: Rahul Raina,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-05-28 13:27:33

Zauważyłem, że używając android:autoLink="web" w ten sposób

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:autoLink="web"/>

Działał OK dla adresów URL, ale ponieważ miałem adres e-mail i numer telefonu, który chciałem połączyć, jak również, skończyło się na użyciu tej linii android:autoLink="all" Jak to

<TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:autoLink="all"/>
I zadziałało jak czar.
 14
Author: aLearner,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-11-14 10:41:27

Upewnij się, że nie używasz setAutoLinkMask(Linkify.ALL), gdy używasz setMovementMethod(LinkMovementMethod.getInstance()) i Html.fromHTML() na odpowiednio sformatowanych linkach HTML (na przykład <a href="http://www.google.com/">Google</a>).

 12
Author: elevenfive,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-09-27 13:00:43

Użyj tego...

TextView.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        Intent in=new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.twitter.com/"));
                        startActivity(in);
                    }

                });

I dodać uprawnienia w pliku manifestu

<uses-permission android:name="android.permission.INTERNET"/>
 11
Author: Tej,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-11-22 09:42:08

Potrzebujesz tylko tego:

android:autoLink="web"

Wstaw ten wiersz do TextView, który można kliknąć w odniesieniu do sieci. Adres URL ustawiony jako tekst tego widoku tekstowego.

Przykład:

 <TextView
    android:id="@+id/textViewWikiURL"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:textStyle="bold"
    android:text="http://www.wikipedia.org/"
    android:autoLink="web" />
 11
Author: Androdos,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-03-25 20:23:47

Przyjęta odpowiedź jest poprawna, ale oznacza to, że numery telefonów, mapy, adresy e-mail i zwykłe linki, np. http://google.com bez tagów href, nie będą już klikalne, ponieważ nie możesz mieć autolink w xml.

Jedynym kompletnym rozwiązaniem, aby mieć wszystko klikalne, które znalazłem, jest następujące:

Spanned text = Html.fromHtml(myString);
URLSpan[] currentSpans = text.getSpans(0, text.length(), URLSpan.class);
SpannableString buffer = new SpannableString(text);
Linkify.addLinks(buffer, Linkify.ALL);
for (URLSpan span : currentSpans) {
    int end = text.getSpanEnd(span);
    int start = text.getSpanStart(span);
    buffer.setSpan(span, start, end, 0);
}
textView.setText(buffer);
textView.setMovementMethod(LinkMovementMethod.getInstance());

I TextView nie powinien mieć android:autolink. Nie ma też potrzeby android:linksClickable="true"; domyślnie jest to prawda.

 11
Author: Kelly McKinnon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-12-01 10:28:13

Tak rozwiązałem klikalne i widoczne linki w widoku tekstowym (kodem)

private void setAsLink(TextView view, String url){
        Pattern pattern = Pattern.compile(url);
        Linkify.addLinks(view, pattern, "http://");
        view.setText(Html.fromHtml("<a href='http://"+url+"'>http://"+url+"</a>"));
    }
 9
Author: Dominic,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-01-24 18:56:46

Użyj poniższego kodu:

String html = "<a href=\"http://yourdomain.com\">Your Domain Name</a>"
TextView textview = (TextView) findViewById(R.id.your_textview_id);
textview.setMovementMethod(LinkMovementMethod.getInstance());
textview.setText(Html.fromHtml(html));
 8
Author: Phuc Tran,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-04-10 04:53:07

[Tested in Pre-lollipop as well as in Lollipop and above]

Możesz pobrać łańcuch HTML z zaplecza lub z plików zasobów. Jeśli umieścisz swój tekst jako ciąg zasobów, upewnij się, że dodasz tag CDATA:

<string name="your_text">![CDATA[...<a href="your_link">Link Title</a>  ...]]</string>

Następnie w kodzie musisz pobrać ciąg znaków i przypisać go jako HTML i ustawić metodę ruchu linków:

String yourText = getString(R.string.your_text);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
   textView.setText(Html.fromHtml(yourText, Html.FROM_HTML_MODE_COMPACT));
} else {
   textView.setText(Html.fromHtml(yourText));
}

try {
   subtext.setMovementMethod(LinkMovementMethod.getInstance());
} catch (Exception e) {
   //This code seems to crash in some Samsung devices.
   //You can handle this edge case base on your needs.
}
 6
Author: Benny,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-04-24 20:20:52

Powodem, dla którego masz problem, jest to, że stara się dopasować tylko "nagie" adresy. rzeczy jak "www.google.com" lub " http://www.google.com".

Uruchamianie tekstu przez Html.fromHtml () powinno wystarczyć. Musisz to zrobić programowo, ale to działa.

 5
Author: Jeremy Logan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-04-30 01:57:32

Nie wiem, czy warto dodać kolejną odpowiedź, ale na wszelki wypadek...

Musiałem upolować to w kilku miejscach, ale w końcu dostałem tę wersję kodu do działania.

Struny.xml:

<string name="name1">&lt;a href="http://www.google.com">link text1&lt;/a></string>
<string name="name2">&lt;a href="http://www.google.com">link text2&lt;/a></string>
Moja aktywność.xml:
<TextView 
    android:id="@+id/textview1"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_marginTop="5dp" />

<TextView 
    android:id="@+id/textview2"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_marginTop="5dp" />
Myactivty.java (in onCreate ()):
TextView tv1 = (TextView)findViewById(R.id.textview1);
TextView tv2 = (TextView)findViewById(R.id.textview2);

tv1.setText(Html.fromHtml(getResources().getString(R.string.name1)));
tv2.setText(Html.fromHtml(getResources().getString(R.string.name2)));
tv1.setMovementMethod(LinkMovementMethod.getInstance());
tv2.setMovementMethod(LinkMovementMethod.getInstance());

Spowoduje to utworzenie dwóch klikalnych hiperłączy z tekstem link text1 i link text2, które przekierują użytkownika do google.

 5
Author: degausser,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-02-16 23:25:14

Dodaj CDATA do zasobu string

Struny.xml

<string name="txtCredits"><![CDATA[<a href=\"http://www.google.com\">Google</a>]]></string>
 5
Author: Akexorcist,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-02-17 11:21:59

Telefon Autolink nie działa na mnie. Poniższe działa jak urok,

TextView tv = (TextView) findViewById(R.id.emergencynos);
String html2="<br><br>Fire - <b><a href=tel:997>997</a> </b></br></br>";        
tv.append(Html.fromHtml(html2));
tv.setMovementMethod(LinkMovementMethod.getInstance());
 4
Author: user1995307,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-04-08 05:08:56

Jeśli korzystasz z TextView opartego na XML, musisz zrobić tylko dwie rzeczy:

  1. Zidentyfikuj swój link w łańcuchu, na przykład " to jest moja strona internetowa." Możesz dodać go w xml lub w kodzie.

  2. W xml, który ma TextView, dodaj te:


android:linksClickable="true"

android:autoLink="web"
 4
Author: codeFood,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-04-11 23:56:17

Używam autolink do "auto podkreślenia" tekstu, ale po prostu zrobiłem "onClick", który zarządza nim. (Sam wpadłem na ten problem)

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:textSize="18dp"
            android:autoLink="all"
            android:text="@string/twitter"
            android:onClick="twitter"/>

public void twitter (View view)
    {
        try
        {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://twitter.com/onaclovtech"));
            startActivity(browserIntent);

        }
        finally
        {
        }
    }

Nie wymaga żadnych uprawnień, ponieważ przekazujesz zamiar do aplikacji, które zarządzają tymi Zasobami, (np.

To mi się udało. Powodzenia.
 3
Author: onaclov2000,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-07-10 12:33:21

Mój kod był taki:

<TextView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/link"
    android:text="@string/forgot"
    android:layout_marginTop="16dp"
    android:gravity="center"
    android:linksClickable="true"/>

Mój kod Javy był taki:

/*TextView action*/
        TextView textView = (TextView) findViewById(R.id.link);
        textView.setMovementMethod(LinkMovementMethod.getInstance());
        textView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(LoginActivity.this,forgot.class));
            }
        });  

To tylko wskazuje link do innej aktywności. Ale ten link jest klikalny i działa płynnie. Testowane w Android Studio 1.5 (podgląd)

 3
Author: Ajay Kulkarni,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-11-09 19:31:43