Android UI 控件详解-TextView(文本视图)
2014-04-05 11:24
483 查看
package com.bdqn.textview; import android.os.Bundle; import android.app.Activity; import android.graphics.Color; import android.widget.TextView; /** * @author TXF * * TextView(文本视图)的实现方式有两种方式。 * 第一种是通过xml布局来实现,第二种是直接通过代码来实现,这里介绍的是通过代码的实现方式. * 通过xml布局文件实现非常简单,只需要在布局文件中添加这样几种参数即可: * TextView对象方法 XML属性 * setTextColor android:textColor * setTextSize android:textSize * setText android:text * setBackgroundResourse android:background * setHight/setWidth android:height/android:width */ public class MainActivity extends Activity { private TextView mtv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // 通过findViewById找到TextView对象 mtv = (TextView) findViewById(R.id.tv); // 定义一个要显示的文本(String类型的) String str = "TextView示例,欢迎使用!"; // 设置文本的颜色,这里Color的首字母一定要大写,否则颜色显示不出来 mtv.setTextColor(Color.BLUE); // 设置文本的大小(尺寸) mtv.setTextSize(20); // 设置文本的背景颜色 mtv.setBackgroundColor(Color.RED); // 要显示的文本 mtv.setText(str); } }
xml布局
<TextView android:id="@+id/tv" android:layout_width="wrap_content" android:layout_height="wrap_content" />
效果图
相关文章推荐
- Android UI系统控件进阶(三)—自动完成文本控件AutoCompleteTextView详解及属性
- Android学习——TextView文本视图的属性详解
- Android UI控件详解-AutoComplete-TextView(自动提示)
- Android UI控件自动提示控件(AutoCompleteTextView)
- android控件详解----TextView(转载)
- Android控件之文本控件---TextView 两种效果+SpannableString
- Android文本控件---TextView和EditView
- Android UI 控件之TextView
- Android控件Editext、TextView属性详解
- 【Android UI控件】EditText属性大全,TextView属性大全
- 步步为营_Android开发课[15]_用户界面之TextView(文本视图)
- Android 开发基础篇——UI——基础控件(TextView、Button、EditText)
- android---textview控件学习笔记之显示表情图片和文本(二)
- [Android新手学习笔记11]-UI控件之TextView
- Android常用控件TextView的属性详解
- Android:UI控件AutoCompleteTextView、MultiAutoCompleteTextView、include、merge、Tokenizer
- Android UI 之TextView控件属性列表
- Android02--Android之UI控件TextView+Button+EditText
- Android基础UI控件之AutoCompleteTextView
- Android UI控件系列:TextView(文本框)