0
我有2個apk,主要和第二個只有第一個apk使用的資源。我試圖誇大佈局無法從共享資源中充氣CardView
mPackName = mContext.getPackageName() + "remote_package_prefix";
mThemeContext = mContext.createPackageContext(mPackName, Context.CONTEXT_IGNORE_SECURITY);
mResources = mThemeContext.getResources();
mInflater = LayoutInflater.from(mThemeContext);
ViewGroup viewGroup = (ViewGroup) mInflater.inflate(mResources.getLayout(getRemoteId(R.layout.remote_layout)), this, true);
,並得到這個錯誤
android.view.InflateException: Binary XML file line #20: Error inflating class <unknown>
Caused by:java.lang.reflect.InvocationTargetException
Caused by:android.content.res.Resources$NotFoundException: Resource ID #0x7f070001
at android.content.res.Resources.getValue(Resources.java:1233)
at android.content.res.Resources.getColor(Resources.java:887)
at android.support.v7.widget.CardView.initialize(CardView.java:228)
at android.support.v7.widget.CardView.<init>(CardView.java:112)
#0x7f070001是CardView
如何解決這個問題?
修訂 CardView XML
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/number_item_padding_h"
android:layout_marginLeft="@dimen/number_item_padding_v"
android:layout_marginRight="@dimen/number_item_padding_v"
android:layout_marginTop="@dimen/number_item_padding_h"
card_view:cardCornerRadius="4dp" />
在這個問題中包含您的佈局文件XML – Booger
我假設它找不到名爲「CardView」的樣式 – Hahaido
您是否包含了gradle依賴項(假設沒有它會編譯)。另外,您是否確保版本與AppCompat版本相匹配(即兩者均爲23.4.1)? – Booger