You can set a shape drawable (a rectangle) as background for the view.
<TextView android:text="Some text" android:background="@drawable/back"/>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#ffffff" />
<stroke android:width="1dip" android:color="#4fa5d5"/>
</shape>
方框
And rectangle drawable back.xml (put into res/drawable folder):
And rectangle drawable back.xml (put into res/drawable folder):
You can use #00000000 for the solid color to have a transparent background. You can also use padding to separate the text from the border. for more information see:http://developer.android.com/guide/topics/resources/drawable-resource.html
圓角框
圓角框
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffffff" />
<corners android:radius="10dp" />
<padding android:left="5dp" android:top="5dp"
android:right="5dp" android:bottom="5dp" />
</shape>
也可以將兩個合起來
也可以將兩個合起來
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#404040" /><!-- 內部填充顏色 -->
<stroke android:width="3dip" android:color="#FFFFFF"/><!--外框顏色 -->
<corners android:radius="10dp" />
<padding android:left="5dp" android:top="5dp"
android:right="5dp" android:bottom="5dp" />
</shape>
沒有留言:
張貼留言