美文网首页APP开发实战
APP开发实战94-Vector静态图的使用

APP开发实战94-Vector静态图的使用

作者: xjbclz | 来源:发表于2016-07-24 21:49 被阅读14次

24.4Vector静态图的使用

把Vector图的XML文件放在drawable文件夹中,就可以使用了:

1ImageView中使用

示例代码如下所示:

Android:id="@+id/image_view"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

app:srcCompat="@drawable/ic_add_shopping_cart_black_24dp"/>

在代码中设置的话,代码如下所示:

ImageViewiv = (ImageView) findViewById(R.id.image_view);

iv.setImageResource(R.drawable.ic_add_shopping_cart_black_24dp);

2TextView和Button

TextView和Button并不能直接使用app:srcCompat来使用Vector图像,需要通过Selector来进行使用,代码如下所示:

ic_add_shopping_cart_black.xml

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:drawableLeft="@drawable/ic_add_shopping_cart_black"

android:text="Hello World!"

android:id="@+id/textView"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="New Button"

android:background="@drawable/ic_add_shopping_cart_black"

android:id="@+id/button"/>

还需在Activity中添加如下代码:

publicclass MainActivity extends AppCompatActivity {

static {

AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);

}

}

参考:http://blog.csdn.net/qq_15545283/article/details/51472458

http://blog.csdn.net/eclipsexys/article/details/51838119

相关文章

网友评论

    本文标题:APP开发实战94-Vector静态图的使用

    本文链接:https://www.haomeiwen.com/subject/fnkgjttx.html