私はRobolectricでアクティビティを構築しようとしていますが、アクティビティのXMLを膨張させることができないため失敗しています。私は以下の問題のあるコンポーネントを含んでいます。私はまだオンラインで満足できる答えを見つけることができませんでした。Androidスタイルを適用するときのRobolectricランタイム例外 - ShadowAssetManager.buildAttribute
カスタムシャドウクラスを作成しようとしましたが、動作しませんでした(https://github.com/robolectric/robolectric/issues/2155#issuecomment-283890626)。
これは、Androidの属性を使用している人なら誰でも実行できる基本的な問題のようですので、ここで何が問題になっているのかは分かりません。以下は
mActivity = Robolectric.buildActivity(TestActivity.class)
.withIntent(intent)
.create()
.get();
問題のある属性のスタイルの下
<ProgressBar
android:id="@+id/blocking_progress_bar"
style="?android:attr/indeterminateProgressStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminate="true"
android:interpolator="@android:interpolator/cycle" />
を含むXMLは、そのスタックトレースです。それはRobolectricのバグだように、私はまだ感じるものの
Caused by: java.lang.RuntimeException: no value for android:attr/indeterminateProgressStyle in theme with applied styles: [Style android:Theme_DeviceDefault (and parents) (forced), Style com.package.name:Theme_XXX (and parents) (forced)]
at org.robolectric.shadows.ShadowAssetManager.buildAttribute(ShadowAssetManager.java:463)
at org.robolectric.shadows.ShadowAssetManager.attrsToTypedArray(ShadowAssetManager.java:532)
at org.robolectric.shadows.ShadowResources$ShadowTheme.obtainStyledAttributes(ShadowResources.java:213)
at android.content.res.Resources$Theme.obtainStyledAttributes(Resources.java)
at android.content.Context.obtainStyledAttributes(Context.java:532)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
EDIT
以下は、私の問題への解決策でした。
style = "?android:attr/indeterminateProgressStyle"からstyle = "@ android:style/Widget.ProgressBar.Small"に変更すると、問題が修正されます。
Robolectric Issue with ProgressBar