这是一个可用于无线电按钮的选择器:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<layer-list>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/ColorPrimaryDark" />
</shape>
</item>
<item>
<layer-list>
<item android:gravity="center_vertical|left" android:left="20dp">
<shape android:shape="oval">
<size android:width="20dp" android:height="20dp" />
<stroke android:color="#ffffff" android:width="2dp" />
</shape>
</item>
<item android:gravity="center_vertical|left" android:left="25dp">
<shape android:shape="oval">
<size android:width="10dp" android:height="10dp" />
<solid android:color="#ffffff" />
</shape>
</item>
</layer-list>
</item>
</layer-list>
</item>
<item android:state_checked="false">
<layer-list>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/ColorPrimary" />
</shape>
</item>
<item android:gravity="center_vertical|left"
android:left="20dp">
<shape android:shape="oval">
<size android:width="20dp" android:height="20dp" />
<stroke android:color="#ffffff" android:width="2dp" />
</shape>
</item>
</layer-list>
</item>
</selector>
在Android API 23中,它看起来如下(应用时):
在Android API 22中,它看起来如下:
有没有办法在API pre-23中定义可绘制的固定大小矢量(即非位图)?
答案 0 :(得分:0)
尝试以下方法以编程方式缩放可绘制对象:
// Read your drawable from somewhere
Drawable dr = getResources().getDrawable(R.drawable.somedrawable);
Bitmap bitmap = ((BitmapDrawable) dr).getBitmap();
// Scale it to 100 x 100
Drawable d = new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(bitmap, 100, 100, true));
// Set your new, scaled drawable "d"