[Android] アプリアイコンをpngじゃなくてshapeで描いてみた

| トラックバック(0) |

Android アプリケーションの(png)アイコンリソースをサイズ別に複数用意するのが大変なので、

リソースレベルでベクター(shape)記述できないか調べてみました。

※2011/12/16 追記:Launcherなどアイコンを必要とするアプリで上手く表示されない場合があるみたいです^^;

 

リソース

  • drawable / icon.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <padding
        android:left="4dip"
        android:top="4dip"
        android:right="4dip"
        android:bottom="4dip" />
    <corners
        android:radius="8dip" />
    <gradient
        android:type="linear"
        android:startColor="#ffff0000"
        android:centerColor="#ff00ff00"
        android:endColor="#ff0000ff"
        android:angle="45" />
</shape>

 

結果

app_icon1.png

 

AndroidManifest.xml ファイル <application> タグ android:icon 属性は、

png ファイル以外にも、(shape を含む)任意の drawable を指定しても反映されるようです。

しかしながら、layer-list を使用した複数の shape 描画ができなかったので、実用的には使えなさそうです。。。^^;

 

おまけ

layer-list のリファレンスのように 1 枚の画像リソースを重ねあわせ描画させることはできるみたいです。

※下図のアプリアイコンには 3 つの★が描画されていますが、使用している png 画像は 1 つです

app_icon2.png

  • drawable / icon.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <bitmap
            android:src="@drawable/star"
            android:gravity="center" />
    </item>
    <item android:top="10dp" android:left="10dp">
        <bitmap
            android:src="@drawable/star"
            android:gravity="center" />
    </item>
    <item android:top="20dp" android:left="20dp">
        <bitmap
            android:src="@drawable/star"
            android:gravity="center" />
    </item>
</layer-list>

 

あわせて読みたい

 

関連記事

トラックバック(0)

トラックバックURL: http://mt.adakoda.com/mt-tb.cgi/561

2016年8月

  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31