Android中TextView中background实现改变样式
时间: 2023-06-18 10:05:35 浏览: 184
在Android中,可以使用`TextView`的`android:background`属性来改变其背景样式。以下是一些示例:
1. 设置纯色背景
```
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF0000"
android:text="Hello World!" />
```
2. 设置圆角矩形背景
```
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/round_rect_background"
android:text="Hello World!" />
```
其中,`@drawable/round_rect_background`是一个自定义的背景资源,定义如下:
```
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="10dp" />
<solid android:color="#FF0000" />
</shape>
```
这个资源定义了一个圆角矩形,并且背景颜色为红色。
3. 设置图片背景
```
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/background_image"
android:text="Hello World!" />
```
其中,`@drawable/background_image`是一个图片资源。
阅读全文
相关推荐















