close

以下記錄怎麼在元件周圍增加邊線與背景,或者說增加線條(增加邊線),該方法是用於 layout 新增框線,下圖是兩個按鈕,可以很明顯看出完全沒有邊線可言。

1.jpg

 

這時候在res/drawable/ 新增一個 xml file,內容如下:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
  <corners
      android:radius="2dp"
      android:topRightRadius="0dp"
      android:bottomRightRadius="0dp"
      android:bottomLeftRadius="0dp" />
  <stroke
      android:width="1dp"
      android:color="@android:color/white" />
</shape>

其中 stroke 代表邊線,width是線條寬度,color則是線條顏色。

 

2.jpg

 

然後在TextView中新增 Android: background屬性如下:

3.jpg

 

這樣就看得到按鈕邊線了:

4.jpg

 

然後新增按鈕的背景其實是同樣的方法,只是要注意到存在 res/drawable/ 裡面的圖檔要png,屬性一樣是使用 background

另外,虛線的屬性如下:

  • android:dashWidth 每條虛線的長度,如不要虛線請設0
  • android:dashGap 每條虛線之間的距離,如不要虛線請設0

 

Reference:

https://stackoverflow.com/questions/8203606/android-how-to-draw-a-border-to-a-linearlayout

https://learnexp.tw/%E3%80%90android%E3%80%91%E4%BF%AE%E6%94%B9%E6%8C%89%E9%88%95%E6%A8%A3%E5%BC%8Fbutton-style%EF%BC%8C%E5%9C%93%E8%A7%92%E6%8C%89%E9%88%95/

 

arrow
arrow

    葛瑞斯肯 發表在 痞客邦 留言(0) 人氣()