ï¼Tips ãTextView ã使ãããªãããã 表示編 ãã ãã®ï¼
TextView ã§å¤å½©ãªè¡¨ç¾ã
ãååã«å¼ãç¶ã TextView ã®è¡¨ç¤ºã®è©±ããã¦ããããã¨æãã¾ãã
ãTextView ã«ãæåã表示ããããç»åãæ·»ããããã¨ãå¯è½ãªãã¨ã¯èª¬æãã¾ãããããããTextView ãæ±ã£ã¦ãããã¡ã«ããã ãã§ã¯ä¸æºãªã±ã¼ã¹ãåºã¦ãã¾ãã
ä¾ãã°ã»ã»ã»
ãNintendo®
ãªã©ã¨è¡¨ç¾ãããå ´åã¯ã«ã©ãããã°ããã®ã§ããããã
ãã®ä»ãæä¸ã«æ°å¼ãç¾ãã«å ´åãªã©ã«ä¸ä»ãæåãä¸ä»ãæåãå©ç¨ããããæä¸ã®ä¸é¨ã®æåã®è²ã大ãããã¹ã¿ã¤ã«ãªã©ãå¤æ´ããããæã«ã¢ã³ãã¼ã©ã¤ã³ãå¼ããããæä¸ã«ç»åãå·®ãè¾¼ã¿ãããã¯ãªãã¯ï¼ã¤ã§Webãµã¤ãã«ãªã³ã¯ããããããªã©æ§ã ãªè¦æãåºã¦ãã¾ãã
ããã®æ§ãªå ´åãé常 Android ã§ã¯ android.text.style.ãSpan ã¨ãã£ããã®ãç¨ãã¦ãã®é½åº¦å¼ã渡ãããã¹ãã«å¤æ´ãå ãã¦ããã¾ãããããèªç±åº¦ã¯ããåé¢ãæç¶ãã¯é¢åã§ãããä½ãããã³ã¼ãããæå½¢å¾ã®å½¢ãä¸ç®ã§ã¯æ³åãè¾ãã¨ããé£ç¹ãããã¾ãã
ããã§ãç»å ´ããã®ã android.text.Html ã¨ããã¯ã©ã¹ã§ãã
http://developer.android.com/reference/android/text/Html.htmlandroid.text.Html ãç¨ã㦠TextView ã«å¤å½©ãªè¡¨ç¾ã
ãä»åããã® Html ã¯ã©ã¹ã§ä½¿ç¨ããã¡ã½ããã¯ï¼ã¤ã§ãã
public static Spanned fromHtml (String source)
public static Spanned fromHtml (String source, Html.ImageGetter imageGetter, Html.TagHandler tagHandler)
å¼æ°ã®æ°ã«éãã¯ããã¾ãã使ãã¡ã½ãã㯠android.text.Html#fromHtml() ã®ã¿ã§ãã
æ»ãå¤ã« android.text.Spanned ã¨ããã¾ããããã㯠CharSequence ã¤ã³ã¿ã¼ãã§ã¤ã¹ãå®è£
ãã¦ãã¾ãã®ã§ TextView#setText() ã TextView#append() ã®å¼æ°ã¨ãã¦ãã®ã¾ã¾æ¸¡ããã¨ãåºæ¥ã¾ãã
第ï¼å¼æ°ã¨ãã¦æ¸¡ãæåå source ã§ãããããã«ã HTML ã¿ã°ãåãè¾¼ãã ããã¹ããã渡ããã¨ã§é¢åãªæç¶ãã代è¡ã§å¦çãã¦ããã¾ãã
fromHtml() ã§ä½¿ããã¿ã°ã¯ï¼
fromHtml() ã§å©ç¨å¯è½ãªã¿ã°ã¯ä¸è¨ã®éãã§ãã
使ç¨å¯è½ãªã¿ã° | <BR>, <P>, <DIV>, <B>, <EM>, <I>, <STRONG>, <CITE>, <DFN>, <BIG>, <SMALL>, <FONT>, <BLOCKQUOTE>, <TT>, <A>, <U>, <SUP>, <SUB>, <H1ãH6>, <IMG> |
---|
æ³¨ï¼ <A> 㨠<IMG> ã«ã¤ãã¦ã¯ãã®ã¾ã¾ã§ã¯ä½¿ãã¾ããã使ç¨æ³ã¯å¾ã»ã©å¥é説æãã¾ãã
åã使ç¨å¯è½ãªå±æ§ã¨è¡¨ç¤ºçµæã¯ä»¥ä¸ã®éãã§ãã
ã¿ã° | 表示çµæ | |
---|---|---|
<BR> | ãªã | æ¹è¡ã |
<P> | ãªã | 段è½ã |
<DIV> | ãªã | <P>ã¨åãã |
<B> | ãªã | 太åã |
<EM> | ãªã | <B>ã¨åãã |
<I> | ãªã | ã¤ã¿ãªãã¯ä½ã§è¡¨ç¤ºãããã |
<STRONG> | ãªã | <I>ã¨åãã ä½æ ãçµæã¯ã¤ã¿ãªãã¯ä½ã æããã³ã¼ãã£ã³ã°ãã¹ã |
<CITE> | ãªã | <I>ã¨åãã |
<DFN> | ãªã | <I>ã¨åãã |
<BIG> | ãªã | ç¸å¯¾çã«æåãµã¤ãºã大ããããã android.text.Html ã§ã¯1.25åã§è¡¨ç¤ºãããããã«è¨å®ããã¦ããã |
<SMALL> | ãªã | ç¸å¯¾çã«æåãµã¤ãºãå°ããããã android.text.Html ã§ã¯0.8åã§è¡¨ç¤ºãããããã«è¨å®ããã¦ããã |
<FONT> | COLOR FACE |
ãã©ã³ãã®è¨å®ã 注æç¹ã¨ã㦠SIZE å±æ§ã«ã¯å¯¾å¿ãã¦ããªãã |
<BLOCKQUOTE> | ãªã | å¼ç¨ææå®ã ã¿ã°ã§å²ã£ãé¨åã®å·¦ç«¯ã«ã©ã¤ã³ã表示ãããã |
<TT> | ãªã | çå¹ ãã©ã³ãã§è¡¨ç¤ºã"monospace"ãæå®ãããã |
<A> | HREF | ãªã³ã¯ã ãã®ã¾ã¾ã§ã¯ã¢ã³ãã¼ã©ã¤ã³ã¨æååã®è²ãå¤åããã ãã§ãªã³ã¯ã¯ãããªãã |
<U> | ãªã | ã¢ã³ãã¼ã©ã¤ã³ã ã¿ã°ã§å²ã£ãç¯å²ã®æååä¸ã«ã©ã¤ã³ãå¼ãããã |
<SUP> | ãªã | ããã¹ããä¸ä»ãæåã¨ãã¦è¡¨ç¤ºã |
<SUB> | ãªã | ããã¹ããä¸ä»ãæåã¨ãã¦è¡¨ç¤ºã |
<H1ãH6> | ãªã | è¦åºãæå®ã ï¼æ®µéã |
<IMG> | SRC | ç»å表示ããã®ã¾ã¾ã§ã¯æå®ãããç»åã¯è¡¨ç¤ºãããªãã æ¿ããã« com.android.internal.R.drawable.unknown_image ã表示ãããã |
<FONT> ã® COLOR å±æ§ FACE å±æ§ã§ä½¿ç¨å¯è½ãªå¤
ã» COLOR å±æ§ã§å®ç¾©æ¸ã¿ã®è²
Black | Grey | Silver | White | Bule | Navy | Teal | Green |
Aqua | Lime | Yellow | Fuchsia | Olive | Purple | Maroon | Red |
注ï¼ãã Grey ãã¯ã Gray ãã®èª¤ãã ã¨æããã¾ããä»å¾ä¿®æ£ãããã§ãããã使ç¨ã«ã¯æ³¨æãã¦ãã ãããåºæ¥ãã ãå®ç¾©æ¸ã¿ã®è²ã§æå®ãããã #RRGGBB ãã使ãæ¹ãè³¢æã§ãã
ã» FACE å±æ§ã§ä½¿ç¨å¯è½ãª Font Family
"monospace", "serif", "sans-serif"
android.text.Html#fromHtml() ã®å ·ä½çãªä½¿ãæ¹
ä¾ã¨ãã¦ããNintendo®ããã表示ãã¦ã¿ã¾ãã
public class TextViewTest extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // HTML ã¿ã°ä»ãæååã®ä½æ String html = "<font color=\"silver\"><b><big>Nintendo</big></b><sup><small>®</small></sup></font>"; // fromHtml() ã®å¼æ°ã«ã¿ã°ä»ãæååã渡ã CharSequence source = Html.fromHtml(html); TextView textview = new TextView(this); // fromHtml() ã®æ»ãå¤ã setText() ã«å¼æ°ã¨ãã¦æ¸¡ã TextView ã«è¡¨ç¤º textview.setText(source); setContentView(textview, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); } }
æåã«HTMLã¿ã°ä»ãã®æååï¼String)ãä½ãã¾ãã<HTML> ã¿ã°ã <HEAD><BODY> ã¿ã°ã¯ä¸è¦ã§ãã次ã«ãããã Html#fromHtml() ã«å¼æ°ã¨ãã¦æ¸¡ãã¦ããã¾ããfromHtml() 㯠static ã¡ã½ããã§ãã®ã§ç´æ¥å¼ã³åºãã¾ããæ»ãå¤ã¯ CharSequence åã§ãã®ã§ããã®ã¾ã¾ TextView#setText() ã«å¼æ°ã¨ãã¦æ¸¡ãã¦ããã¾ãã
以ä¸ã§ãã é©ãã»ã©ç°¡æ½ã§ããã
çµæã¯ãããªãã¾ãã»ã»ã»
次ã«ãæ§ã ãªã¿ã°ã使ã£ã¦ã¿ã¾ãã»ã»ã»
å¶éã¯ããã¾ãããããã ãåºæ¥ãã°é常ã®ä½¿ç¨ã«ã¯ååã§ãããã
<A> ã¿ã°ã¨ <IMG> ã¿ã°ã®ä½¿ç¨æ³
ã»ã»ã»ãæ¸ãã¤ããã§ãããã表çµã¿ã«çµæ§ãªæéãé£ã£ã¦ãã¾ãã»ã»ã»ä»åã¯ããã¾ã§ã¨ãã¾ãã
次åã¯ã»ã»ã»
ããããããã§ã次ã¯ã <A> ã¿ã°ã¨ <IMG> ã¿ã°ã®ä½¿ç¨æ³ ããããã¾ãã