我知道使用第三方庫,在Android中使用SVG圖像是可能的。 庫:svg

載入SVG映像的代碼如下所示:public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

//Create a new ImageView

ImageView imageView = new ImageView(this);

//Set the background color to white

imageView.setBackgroundColor(Color.WHITE);

//Parse the SVG file from the resource

SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.android);

//Get a drawable from the parsed SVG and set it as the drawable for the ImageView

imageView.setImageDrawable(svg.createPictureDrawable());

//Set the ImageView as the content view for the Activity

setContentView(imageView);

}

工作正常我可以看到圖像。 但是現在我想在運行時改變svg圖像的顏色。 為此,我嘗試了相同項目描述中提到的代碼。//0xFF9FBF3B is the hex code for the existing Android green, 0xFF1756c9 is the new blue color

SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.android, 0xFF9FBF3B, 0xFF1756c9);

但是我無法看到顏色的變化。 所以我想知道在Java文件中動態改變顏色是有可能的。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐