如何在 Android 中使用圓背景形狀繪製勾號?
本例展示如何在 android 中使用圓背景形狀繪製勾號。
步驟 1 − 在 Android Studio 中建立新專案,轉到 檔案 ⇒ 新建專案,填寫必要細節建立新專案。
步驟 2 − 在 res/layout/activity_main.xml 中新增以下程式碼。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center" android:layout_marginTop="30dp" tools:context=".MainActivity"> <ImageView android:layout_width="100dp" android:layout_height="100dp" android:background="@drawable/background"/> </LinearLayout>
在上述程式碼中,我們添加了 image view 並在其中添加了 background.xml 作為背景。
步驟 3 − 在 drawable/ background.xml 中新增下列程式碼
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:autoMirrored="true" android:viewportWidth="426.667" android:viewportHeight="426.667"> <path android:fillColor="#6AC259" android:pathData="M213.333,0C95.518,0 0,95.514 0,213.333s95.518,213.333 213.333, 213.333c117.828,0 213.333,-95.514 213.333,-213.333S331.157, 0213.333,0zM174.199,322.918l-93.935,-93.931l31.309,-31.309l62.626, 62.622l140.894,-140.898l31.309,31.309L174.199,322.918z" /> </vector>
嘗試執行你的應用程式。我假設你已將真實的 Android 移動裝置連線到了計算機。要從 Android Studio 執行該應用程式,開啟其中一個專案的活動檔案,然後單擊工具欄中執行 圖示。選擇你的移動裝置作為選項,然後檢視你的移動裝置,它將顯示你的預設螢幕 -
單擊 此處 下載專案程式碼
廣告