Created
August 10, 2016 14:52
-
-
Save ParkSangGwon/c16913b4b786e57d3ae6cc0e247c2c39 to your computer and use it in GitHub Desktop.
Linkify로 TextView의 특정단어 클릭시 URL이동시키기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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