2014-09-28 46 views
1

我創建了一個小型計算器應用程序。 這樣目前,它顯示的按鈕: enter image description here帶多個文本的按鈕

我想表明它是這樣的:

enter image description here

兩兩件事:

1)如何使罪^ -1不同的顏色+上標,以便用戶知道長按會導致他使用逆。 2)在上標中寫入-1。

+0

因此,-1應該是一個超級超級腳本? – 2014-09-28 10:20:18

回答

3

嘗試使用HTML。

罪按鈕 -

sinbutton.setText(Html.fromHtml("sin<span style="color:blue"><sup>sin<sup>-1</sup></sup></span>")); 

類似地,對於其它按鈕 -

COS -

cosbuttton.setText(Html.fromHtml("cos<span style="color:blue"><sup>cos<sup>-1</sup></sup></span>")); 

黃褐色 -

tanbutton.setText(Html.fromHtml("tan<span style="color:blue"><sup>tan<sup>-1</sup></sup></span>")); 
0

使用方法如下:您可以根據需要設置和設置文本的格式。

btn.setText(Html.fromHtml("sin<font color='red'><sup>-1</sup></font>")); 
-1

在字符串

<string name="sin">sin</string> 
<string name="_1">-1</string> 

在的onCreate()

sinButton.setText(Html.fromHtml(getResources().getString(R.string.sin)+"<sup><font color='#FF0000'>"+getResources().getString(R.string.sin)+"<sup>"+getResources().getString(R.string._1)+"</sup>"+"</font></sup>")); 
+0

嘿!向下投票!你能告訴我你爲什麼投下我的答案嗎? – Hemanth 2014-09-28 16:16:06