[英]How to set drawables vector asset as my activity background?
我正在尝试将矢量资产设置为背景,但出现错误 logcat
logcat 图像logcat
Caused by: android.view.InflateException: Binary XML file line #18: Binary XML file line #18: Error inflating class ImageView Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class ImageView Caused by: android.content.res.Resources$NotFoundException: Drawable in.technicalkeeda.login_design:drawable/ic_testback with resource ID #0x7f060057 Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_testback.xml from drawable resource ID #0x7f060057 在 android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:854)
主要活动
package in.technicalkeeda.login_design;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
使用-->
android:src="@drawable/ic_testback"
而不是srcCompat
设置活动的内容视图后,通过以下代码设置活动的根视图的背景。
View root = getWindow().getDecorView().findViewById(android.R.id.content)
root.setBackgroundResource(R.drawable.ic_testback);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.