參考: http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape
利用shape可以製作出好看的圓角方框Widget元件
Step1. 先產生一個描述shape的 roundbox.xml
Eclipse>File>new>Android XML File (resource type選drawable)
會在res>drawable產生一roundbox.xml
- startcolor到endcolor是背景的漸層色,此例設成透明白色不漸層,若要漸層把start和end的color設成不一樣就可以了
- 產色的格式是#AARRGGBB
- AA: 透明度
- RR: 紅色
- GG: 綠色
- BB: 藍色
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#33FFFFFF"
android:endColor="#33FFFFFF"
android:angle="45"/>
<padding android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp" />
<corners android:radius="5dp" />
</shape>
Step2. 套用到元件的background
<TextView
android:id="@+id/textViewMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/roundbox"
android:text="@string/widgetTestString"
android:textColor="@color/Black"
android:textSize="@dimen/font8dp"
/>
完成 ^^
沒有留言:
張貼留言