I have a TextView
with android:autoLink="all"
:
<TextView
android:id="@+id/text"
android:text="abcdefgh@def.com"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="all" />
For some reason I want to open a link set in android:text
(it may be phone number, email, etc.). When I run an application, a performClick()
doesn't open the link.
TextView textView = findViewById(R.id.text);
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.performClick();
Linkify.addLinks(buffer, Linkify.ALL);
and some others don't help.
UPDATE
Thank you for replies. Show my code after receiving 3 answers. I use API 19, 25 emulators and device (API 21). Sadly, nothing works.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/text"
android:text="abcdefgh@def.com"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:autoLink="web|email|phone" />
</android.support.constraint.ConstraintLayout>
MainActivity:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView text = findViewById(R.id.text);
int mask = Linkify.ALL;
Linkify.addLinks(text, mask);
text.setMovementMethod(LinkMovementMethod.getInstance());
text.performClick();
}
}