TextView就是用来显示文本标签的控件,修改使用TextView显示文本的颜色、大小等属性。

实例代码:
xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <TextView
        android:id="@+id/textview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:textSize="18sp"
        android:text="@string/hello"/>
</LinearLayout>
 
Activity:
public class MainActivity extends AppCompatActivity {
    /**
     * 声明TextView控件对象
     */
    private TextView mTextView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mTextView = findViewById(R.id.textview);
        // 设置TextView显示文本
        String helloTextView = "TextView实例,欢迎使用!";
        // 设置文本的颜色
        mTextView.setTextColor(getResources().getColor(R.color.red));
        // 设置文本字体大小
        mTextView.setTextSize(20);
        // 设置文本字体背景
        mTextView.setBackgroundColor(getResources().getColor(R.color.blue));
        // 设置文本字体背景
        mTextView.setText(helloTextView);
    }
} 
因为在代码清单中使用了fundViewById来获得TextView对象,因此在布局文件“activity_main.xml”中需要指定TextView资源的ID
TextView对象方法与对应的XML属性
| TextView对象方法 | XML属性 | 
| setTextColor | android:textColor | 
| setTextSize | android:textSize | 
| setText | android:text | 
| setBackgroundResource | android:background | 
| setHeight/setWidth | android:height/android:width | 
效果图:



![[附源码]计算机毕业设计基于springboot的残障人士社交平台](https://img-blog.csdnimg.cn/e2c1757cf3184c4fada58934dfff9f9a.png)







![[附源码]计算机毕业设计JAVA医药管理系统](https://img-blog.csdnimg.cn/d8d2cad4211d4e8ca258ad6f9ac2bd18.png)


![[附源码]计算机毕业设计JAVA医院床位管理系统](https://img-blog.csdnimg.cn/07358283159d418cb19376b0f9f84f83.png)





