1

想問。什麼是從資源使用VectorDrawable的正確方法? 與支持庫compile 'com.android.support:support-v4:25.1.1'從代碼中使用VectorDrawable資源

由於getDrawable()已被棄用,當我使用ContextCompat.getDrawable(this, R.drawable.ic_cancel_button);用於設定工具欄導航圖像這樣

if(toolbar != null) 
{ 
toolbar.setNavigationIcon(ContextCompat.getDrawable(this, R.drawable.ic_cancel_button)); 
} 

錯誤occures。

Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_cancel_button.xml from drawable resource ID #0x7f02005e 
+0

您可以使用這個:ResourcesCompat.getDrawable(getResources(),R.drawable.your_drawable,null) –

回答

相關問題