String & StyledText

old/UI Design 2010. 6. 30. 20:09
1. html tag 사용

[strings.xml]
    <string name="ex1">"This'll work"</string>
    <string name="ex2">This\'ll work</string>
    <string name="ex3">This <b><i>work</i></b></string>

2. html encoding 사용

[styledStrings.java]
       String escapedTitle = TextUtils.htmlEncode("as");
        String resultsTextFormat = this.getResources().getString(R.string.ex4);
        String resultsText = String.format(resultsTextFormat,1,escapedTitle);
        CharSequence styledResults = Html.fromHtml(resultsText);
       
        LayoutInflater inflater = LayoutInflater.from(this);
       
        View layout = inflater.inflate(R.layout.main, (ViewGroup) findViewById(R.id.root));
        TextView text = (TextView) layout.findViewById(R.id.htmlStr);
        text.setText(styledResults);
       
        setContentView(layout);

[strings.xml]
    <string name="ex4">%1d results for &lt;b>%2$s&lt;/b></string>


'old > UI Design' 카테고리의 다른 글

Resources - Menus, Searchable  (0) 2010.07.01
Resources - Dimen, Color, 9-patch, Animation  (0) 2010.07.01
Style & Theme  (0) 2010.06.30
Notification  (0) 2010.06.17
UI 이벤트 처리  (0) 2010.06.15
Posted by jazzlife
,