秀气龙

专心、专注、努力

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

TextView控件是一个文本控件,用来显示一个文本标签的控件。

下面用一段代码来演示一下TextView的使用方法

XML布局文件

<!-- 设置显示的文本控件 -->
<TextView
android:id="@+id/mytextview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/text"
/>

源码文件

public class TextViewActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/*获得testview对象*/
TextView testview = (TextView)findViewById(R.id.mytextview);
/*设置testview的文本颜色*/
testview.setTextColor(Color.RED);
/*设置testview字体大小*/
testview.setTextSize(20);
/*设置testview的背景颜色*/
testview.setBackgroundColor(Color.BLUE);

}
}

具体的在代码中都由注释。用代码来说明一切吧。!!

 

posted on 2011-11-09 03:44  秀气龙  阅读(209)  评论(0)    收藏  举报