【发布时间】:2017-07-26 23:18:49
【问题描述】:
我正在尝试在 Robolectric 中构建一个 Activity,但由于未能为该 Activity 的 XML 充气而失败。我在下面包含了有问题的组件。我还没有在网上找到满意的答案。
我尝试过创建自定义 Shadow 类,但没有成功 (https://github.com/robolectric/robolectric/issues/2155#issuecomment-283890626)。
这似乎是任何使用 Android 属性的人都会遇到的基本问题,所以我不太确定这里出了什么问题。
mActivity = Robolectric.buildActivity(TestActivity.class)
.withIntent(intent)
.create()
.get();
以下是包含违规属性样式的 XML
<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" />
下面是堆栈跟踪。
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)
编辑
以下是我的问题的解决方案,尽管我仍然觉得这是一个 Robolectric 错误。
从 style="?android:attr/indeterminateProgressStyle" 更改为 style="@android:style/Widget.ProgressBar.Small" 解决了这个问题。
【问题讨论】:
标签: android android-styles robolectric android-progressbar