2011年1月15日星期六

如何通過Html.fromHtml()方法顯示兩行文字在按鈕之上

android.text.Html類把HTML字符串轉換成可顯示的樣式文本. (並非所有的HTML標記都支持)

例子:

通過Html.fromHtml()方法顯示兩行文字在按鈕之上

package com.AndroidDualLineButton;

import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.widget.Button;

public class AndroidDualLineButton extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button myButton = (Button)findViewById(R.id.mybutton);
myButton.setText(Html.fromHtml("<b>" + "Line One" + "</b>" + "<br />" + "<small>" + "Line Two" + "</small>"));

}
}




2 則留言: