[Pin to the top] portal of textview of Android Xuan Tie Jian

Source: Internet
Author: User

 

Portal: Previous section

 

Xuan tiejian
Jin Yong, the first martial arts sword! The yundun is an exclusive game of the World. After the age of 40, the yundun is the hero of the artifact. Before the treasure of the gods, the sword was given to Xiao dongxie Guo yu. Before Xiangyang City broke, Guo Jing and Huang Rong and his wife invited the High-tech craftsman to build the yitianjian, the Dragon Sword and the two God soldiers, and hidden in the "9 Yin Zhenjing", "down the Dragon 18 palm spectrum" and "Wu Mu's suicide note. The longer the sword is, the longer it is, the longer it is on both sides of the Jianfeng are blunt mouth, the sword tip circle is like a hemisphere, dark black through the body, but invisible red light. The sword is made of Xuan tie, weighing catties. Xuan tie is the best in the world, is to get one or two is also difficult, unusual swords and swords, as long as the addition of half a few dollars, Fan tie became a powerful weapon. "No charge, no failure, no failure", the realm is far better than the world's most ingenious sword moves. The more calm the sword moves, the more difficult the other party to resist. As long as the strength is strong and fierce, the power is far greater than the changing magic of the sword.

In this section, we will learn how to use the Android platform "text" textview to navigate to an activity. The following example shows the scenario:

I. Key technical points of the case

1. Android. Text. spannablestring: provides an overall text that is immutable, but supports local objects (marked by it) that can be appended or separated.

2. spannablestring class setspan (...): Set the link address, link display content, and additional content application effect.

3. spanned. span_exclusive_exclusive: the new characters in the front-end and back-end of the current text do not use the current display effect.

4. Android. Text. method. linkmovementmethod: Provides the hyperlink function. When textview needs this function, you can introduce the instance of this class.

Ii. Case studiesCodeDisplay

Androidmanifest. xml

 
   
    
    
     
      
       
       
      
     
     
     
    
   

Strings. xml

 
<Resources> <string name = "app_name"> textview click the link to bring up the activity </string> </resources>

Main. xml

 
<? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: Orientation = "vertical" Android: layout_width = "match_parent" Android: layout_height = "match_parent"> <textview Android: id = "@ + ID/TV1" Android: layout_width = "match_parent" Android: layout_height = "wrap_content" Android: textsize = "20sp"/> <textview Android: id = "@ + ID/TV2" Android: layout_width = "match_parent" Android: layout_height = "wrap_content" Android: textsize = "20sp" Android: layout_margintop = "20dp"/> </linearlayout>

Textviewmainactivity. Java

Package COM. android. textview; import android. app. activity; import android. content. intent; import android. OS. bundle; import android. text. spannablestring; import android. text. spanned; import android. text. method. linkmovementmethod; import android. text. style. clickablespan; import android. view. view; import android. widget. textview;/*** textview Case 3: click the link to bring up activity * @ author lynnli1229 */public class textviewmainactivity extends activity {private textview textview1, textview2; @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); textview1 = (textview) findviewbyid (R. id. TV1); textview2 = (textview) findviewbyid (R. id. TV2); string textstr1 = "click to link to textviewoneactivity"; string textstr2 = "click to link to textviewtwoactivity"; // split the string spannablestring SS1 = new spannablestring (textstr1 ); spannablestring ss2 = new spannablestring (textstr2); ss1.setspan (New clickablespan () {@ override public void onclick (view widget) {intent = new intent (textviewmainactivity. this, textviewoneactivity. class); startactivity (intent) ;}}, 0, textstr1.length (), spanned. span_exclusive_exclusive); ss2.setspan (New clickablespan () {@ override public void onclick (view widget) {intent = new intent (textviewmainactivity. this, textviewtwoactivity. class); startactivity (intent) ;}}, 0, textstr2.length (), spanned. span_exclusive_exclusive); textview1.settext (SS1); textview2.settext (ss2); textview1.setmovementmethod (linkmovementmethod. getinstance (); textview2.setmovementmethod (linkmovementmethod. getinstance ());}}

Textviewoneactivity. Java

 
Package COM. android. textview; import android. app. activity; import android. OS. bundle; public class textviewoneactivity extends activity {@ override protected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); settitle ("this is textviewoneactivity ");}}

Textviewtwoactivity. Java

 
Package COM. android. textview; import android. app. activity; import android. OS. bundle; public class textviewtwoactivity extends activity {@ override protected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); settitle ("this is textviewtwoactivity ");}}

Iii. Demonstration of case Effects


Portal: Next section

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.