将可绘制对象加载到片段中



我有一个 LinearLayout,我想设置一个可绘制的背景

fragments.add(new FragmentTypeC().newInstance(getString(R.string.Historie6_header), R.drawable.london_old_stock_exchange));

但它说在这一行中抛出了一个 NULLPointerException,并且找不到资源。这是我的创建视图:

     View root = inflater.inflate(R.layout.fragment_type_c, container, false);
    webViewHeader = (WebView) root.findViewById(R.id.header_type_c);
    imageLayout = (LinearLayout) root.findViewById(R.id.layout_type_c);
    webViewHeader.loadDataWithBaseURL("file:///android_asset/", loadHTLMContentHeader(header), "text/html; charset=utf-8", "utf-8", null);
    webViewHeader.setBackgroundColor(0x00000000);
    imageLayout.setBackground(ResourcesCompat.getDrawable(getResources(), picId, null));

    return root;
}

有人知道我如何解决它吗?

尝试使用这个

imageLayout.setBackgroundResource(picId);

最新更新