[Android]Vector Assetに枠線をつける方法
3469 ワード
初めに
AndroidのVectorDrawableを利用することであらかじめ用意されている画像を簡単に利用できます。
そのVectorDrawableに枠線をつける方法をまとめていきます。
VectorDrawableの作成
Android StudioのVector Assetでデフォルトで作成されるのは以下のようなxmlになります。
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"
/>
</vector>
このxmlによって作成されるDrawableリソースは以下のようになります。
枠線をつける
以下のように変更することで枠線をつけることができます。
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"
android:strokeWidth="1"
android:strokeColor="@android:color/holo_red_dark" />
</vector>
変更箇所
枠線をつけるにあたり変更した個所について説明します。
tint:リソース全体を着色
strokeWidth:枠線の太さをFloat型で指定
strokeColor:枠線の色を指定
参考
Author And Source
この問題について([Android]Vector Assetに枠線をつける方法), 我々は、より多くの情報をここで見つけました https://qiita.com/kurramkurram/items/760001da2cd43fc4a821著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .