textView 하이퍼링크 추가(두 가지 구현 방식)
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(this);
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
TextView textView = new TextView(this);
String html = " :
";
html+="<a href='http://www.baidu.com'> </a>";// , http://。
// , activity, activity , 。
CharSequence charSequence = Html.fromHtml(html);
textView.setText(charSequence);
textView.setMovementMethod(LinkMovementMethod.getInstance());
layout.addView(textView);
this.setContentView(layout,params);
}
두 번째
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(this);
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
TextView textView = new TextView(this);
String html = " :
";
html+="www.baidu.com";// HTTP; 。
textView.setText(html);
textView.setAutoLinkMask(Linkify.ALL);
textView.setMovementMethod(LinkMovementMethod.getInstance());
layout.addView(textView);
this.setContentView(layout,params);
}
요약하면 html로 하이퍼링크를 표시하려면 반드시 전체 URL을 써야 한다.setAutoLinkMask(Linkify.ALL)로 다 쓰지 않아도 자동으로 식별할 수 있다.이 두 가지 방법은 모두 set Movement Method를 설정해야만 점프할 수 있다.또한 setAutoLinkMask는 하이퍼링크를 식별할 뿐만 아니라 전화번호 등도 포함한다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Java PowerPoint에서 하이퍼 링크 만들기이번에는 PowerPoint에서 하이퍼 링크를 만드는 방법을 소개합니다. 거기에 Spire.Presentation for Java라는 라이브러리가 필요합니다. 웹 사이트, 이메일 주소, 다른 PowerPoint 슬라...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.