Ich versuche, eine Aktivität in Robolectric zu erstellen, aber es schlägt fehl, weil das XML der Aktivität nicht aufgebläht wurde. Ich habe die beanstandeten Komponenten unten aufgeführt. Ich konnte online noch keine befriedigende Antwort finden.Robolectric RuntimeException beim Anwenden des Android-Stils - ShadowAssetManager.buildAttribute
Ich habe versucht, benutzerdefinierte Shadow-Klassen zu erstellen, aber das hat nicht funktioniert (https://github.com/robolectric/robolectric/issues/2155#issuecomment-283890626).
Dies scheint ein grundlegendes Problem zu sein, dass jeder, der die Android-Attribute verwendet, in sich trägt, also bin ich mir nicht wirklich sicher, was hier falsch läuft.
mActivity = Robolectric.buildActivity(TestActivity.class)
.withIntent(intent)
.create()
.get();
Unten ist die XML-Attribut wird der säumige Stil
<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" />
Unten enthält, ist, dass Stack-Trace.
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
Nachfolgend wurde die Lösung für mein Problem, obwohl ich immer noch ein Robolectric Bug ist das Gefühl, es.
Wechseln von style = "? Android: attr/indeterminateProgressStyle" zu style = "@ android: style/Widget.ProgressBar.Small" behebt das Problem.
Robolectric Issue with ProgressBar