標籤:android style blog http color io ar 使用 sp
加一個紅色的邊框:
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" android:paddingLeft="20dp" android:paddingRight="20dp" > <!-- 通過android:background指定背景 --> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="帶邊框的文本" android:textSize="24sp" android:background="@drawable/bg_border" /></LinearLayout>
邊框XML:(建立檔案夾drawable.然後在此檔案夾下建立檔案bg_border.xml)
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 設定紅色邊框 --><stroke android:width="2dp" android:color="#f00"/></shape>
效果
漸層顏色:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <!-- 指定圓角矩形的4個圓角的半徑 --> <corners android:topLeftRadius="5dp" android:topRightRadius="5dp" android:bottomLeftRadius="5dp" android:bottomRightRadius="5dp" /> <!-- 指定邊框線條的寬度和顏色 --> <stroke android:width="4dp" android:color="#f0f"/> <!-- 指定使用漸層背景色,使用sweep類型的漸層,顏色從紅色到綠色再到藍色 --> <gradient android:startColor="#f00" android:centerColor="#0f0" android:endColor="#00f" android:angle="270" android:centerX="0.5" android:centerY="0.5" /></shape>
效果:
說明:
(1)shape節點配置的是圖形的形式,主要包括方形、圓形等
(2)gradient節點主要配置起點顏色、終點顏色及中間點的顏色、座標、漸層效果(0,90,180從左至右漸層,270從上到下漸層)預設從左至右。
(3)corners節點配置四周圓角的半徑。
android 圓角邊框、漸層背景的TextView