1

I want to show user text-data opened in edittext where text is stylish. Like, some words are bold , some are italiac , lines are colored differently based on user preferences etc.. How can I show such stylish data to user ; is it possible using edittext ?

Also, is there a way I can embed CSS like quality in my app without its interaction with web. I just want to create a beautiful and colorful app. Please provide any tips. I'm too new to android.

Thanks.

4

2 回答 2

3

您可以使用 Spannable String。

   EditText et = (EditText) findViewById(R.id.ed);  
  String s= "Hello Everyone";
  SpannableString ss1=  new SpannableString(s);
  ss1.setSpan(new RelativeSizeSpan(2f), 0,5, 0);
  ss1.setSpan(new ForegroundColorSpan(Color.RED), 0, 5, 0); 
  ss1.setSpan(new StyleSpan(Typeface.ITALIC), 0, 5, 0); 
  ss1.setSpan(new StyleSpan(Typeface.BOLD), 0, ss1.length(), 0);
  ss1.setSpan(new ForegroundColorSpan(Color.RED), 0, ss1.length(), 0); 
  et.append(ss1); 

在此处输入图像描述

有关更多样式检查链接@ http://blog.stylingandroid.com/archives/177

于 2013-06-03T11:58:35.750 回答
0

您可以使用 TTF 文件并存储在您的资产文件夹中。

 Typeface font = Typeface.createFromAsset(getAssets(),"Tangerine_Regular.ttf");
 nametodisplay.setTypeface(font);

nametodisplay 是一个文本视图。为edittext尝试类似的方法。不过我自己从未尝试过。

于 2013-06-03T11:53:56.763 回答