2014-12-13 49 views
2
MyButton.setText(Html.fromHtml("* <small><sup>^</sup></small>")); 

使用Eclipse后不工作如果我使用其他方法是相同的:HTML文本(或spannable)迁移到Android工作室

SpannableStringBuilder cs = new SpannableStringBuilder("* ^");  
cs.setSpan(new SuperscriptSpan(), 1, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
cs.setSpan(new RelativeSizeSpan((float) 0.50), 1, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
MyButton.setText(cs); 

MUY buid.graddle配置为:

android { 
    compileSdkVersion 18 
    buildToolsVersion "21.1.2" 

感谢您的帮助!

+0

你不应该使用3,而不是4 1,4? – pskink 2014-12-13 18:17:47

+0

我使用的是html模式。问题不在于编程,而是向Android Studio迁移! – 2014-12-13 18:31:13

+0

它是相同的设备API版本,如果是的话,哪一个? – pskink 2014-12-13 18:43:06

回答

0

问题不在于迁移。我创建了一个新的程序与AS:

LinearLayout ly = new LinearLayout(this); 

    Button b = new Button(this); 
    b.setText(Html.fromHtml("* <small><sup>^</sup></small>")); 

    ly.addView(b); 

    TextView tv = new TextView(this); 
    tv.setText(Html.fromHtml("* <small><sup>^</sup></small>")); 

    ly.addView(tv); 

    setContentView(ly); 

结果与Android工作室:

enter image description here

它是工作在TextView的,但在按钮上标为“^”字符不存在。 eclipse中的相​​同代码对于textview和按钮都运行良好。

我使用AS 1.0.1和我的buid.graddle配置为:

android { 
    compileSdkVersion 21 
    buildToolsVersion "21.1.2" 

感谢您的帮助!

+0

@pskink问题与简单的html标签相同: b.setText(Html.fromHtml(“A A”)); – 2014-12-14 11:58:03

+1

**解答**:加入 ** b.setAllCaps(false); ** 解释:http://stackoverflow.com/questions/24880388/cannot-lower-case-button-text-in-android -studio?rq = 1 – 2014-12-14 15:14:55

0

试试这个...

Button byButton = new Button(this); 
byButton.setText(Html.fromHtml(" * <small><sup>^</sup></small>")); 
+0

同样的结果,它不工作... – 2014-12-14 11:15:19