android widget之TextView
2011-09-25 19:30
232 查看
Android中的TextView 其实相当于很多语言中Label (比如Java Swing 的JLabel),主要是用于显示一个字符串。 比如:
<TextView android:id="@+id/lable1"
android:text="This is a Label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#cc0000"
android:textColor="#ffffff"
android:textSize="16sp"
android:padding="10dip"/>
其中 android:background 设置TextView的背景颜色,
android:textColor 设置TextView的文字颜色。
android:textSize 设置TextView的字体大小。
效果如下:
如果要动态设置TextView的字符串,可以通过程序实现:
TextView tv = (TextView)findViewById(R.id.lable1);
tv.setText("setText ");
<TextView android:id="@+id/lable1"
android:text="This is a Label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#cc0000"
android:textColor="#ffffff"
android:textSize="16sp"
android:padding="10dip"/>
其中 android:background 设置TextView的背景颜色,
android:textColor 设置TextView的文字颜色。
android:textSize 设置TextView的字体大小。
效果如下:
如果要动态设置TextView的字符串,可以通过程序实现:
TextView tv = (TextView)findViewById(R.id.lable1);
tv.setText("setText ");
相关文章推荐
- ClassCastException: android.widget.ImageView cannot be cast to android.widget.TextView
- android.widget.TextView 属性详解
- android用Adapter实现ListView的初始化报错android.widget.LinearLayout cannot be cast to android.widget.TextView
- java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView
- void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
- java.lang.ClassCastException: android.widget.ImageView cannot be cast to android.widget.TextView解决办法
- Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.Bu
- android.widget.TextView.setText()
- APP程序崩溃错误为Android.widget,textView cannot be cast to android.widget.button
- void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
- Caused by: java.lang.ClassCastException: android.widget.TextView修复
- void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
- java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText
- java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText
- java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.LinearLayout
- .ClassCastException: .LinearLayout cannot be cast to android.widget.TextView
- (android problem)can't cast android.widget.linearlayout to android.widget.textview
- 【bug】java.lang.NoSuchMethodError: android.widget.TextView.setBackground
- 【Android】程序崩溃错误为Android.widget,textView cannot be cast to android.widget.button
- java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setTe