The first method: Create a new file under the Drawable folder to set the background style
Code:
Create a new Text_view_border.xml under the Drawable folder
[Java]View Plaincopy
- <?xml version="1.0" encoding="UTF-8"?>
- <shape xmlns:android="http://schemas.android.com/apk/res/android" >
- <solid android:color="#80858175"/>
- <stroke android:width="1dip" android:color= "#aea594"/>
- <corners android:topleftradius="2DP"
- android:toprightradius="2DP"
- android:bottomrightradius="2DP"
- android:bottomleftradius="2DP"/>
- </shape>
Called in the layout file
[Java]View Plaincopy
- <textview
- android:id="@+id/tv"
- Android:layout_width="Wrap_content"
- android:layout_height="Wrap_content"
- android:background="@drawable/text_view_border"/>
Called in the class file:
[Java]View Plaincopy
- Tv.setbackgroundresource (R.drawable.text_view_border);
Analysis:
Solid sets the fill color, and the color value begins with #80 to indicate transparency
Stroke set Border width, color value
Corners setting rounded corners
Second method: Set background with picture