Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Linkify로 TextView의 특정단어 클릭시 URL이동시키기
<RelativeLayout 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"
android:padding="@dimen/activity_vertical_margin"
>
<TextView
android:id="@+id/tvLinkify"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</RelativeLayout>
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tvLinkify = (TextView) findViewById(R.id.tvLinkify);
String text = "안녕하세요. 셀폰서비스를 운영중인 박상권입니다.저는 박상권의 삽질블로그를 운영하고 있습니다.";
tvLinkify.setText(text);
Linkify.TransformFilter mTransform = new Linkify.TransformFilter() {
@Override
public String transformUrl(Matcher match, String url) {
return "";
}
};
Pattern pattern1 = Pattern.compile("셀폰");
Pattern pattern2 = Pattern.compile("박상권의 삽질블로그");
Linkify.addLinks(tvLinkify, pattern1, "http://selphone.co.kr",null,mTransform);
Linkify.addLinks(tvLinkify, pattern2, "http://gun0912.tistory.com/",null,mTransform);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment