天天看點

Android菜鳥進擊之路(一)——設定布局為透明圓角矩形

Android菜鳥進擊之路(一)——設定布局為透明圓角矩形

一、在res->drawable-mdpi檔案夾下建立一個xml檔案。idea這個軟體建立的時候沒有字尾為.xml的檔案,需要手動建立。

1、選擇file->settings

2、Editor->File and Code Templates->中間圖形框選擇Files->點選+添加模闆->輸入模闆名字Name:XML File.xml(可以自定義)->Extension:xml(字尾名)->在面闆中輸入内容:

<?xml version="1.0" encoding="UTF-8"
<configuration>

</configuration>
           

->勾選上enable live templates->Apply->ok

Android菜鳥進擊之路(一)——設定布局為透明圓角矩形

3、選擇drawable-mdpi檔案,建立xml檔案(即剛剛自己添加的模闆)

二、在xml檔案中添加如下内容

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
   <solid android:color="#88ffffff"/>
    <corners android:topLeftRadius="10dp"
    android:topRightRadius="10dp"
    android:bottomRightRadius="10dp"
    android:bottomLeftRadius="10dp"/>
</shape>
           

shape是安卓xml資源檔案裡的一種常用标簽,其檔案通常存放于drawable下。通常用來繪制一些簡單的背景圖檔。用于設定布局的填充顔色,用于設定布局的四個角為弧形。

三、在需要設定成圓角的布局或者控件中添加屬性: