我和朋友一起创建了一个Android应用程序,我有一个与UI相关的奇怪问题.
当在片段之间切换时,有时UI倾向于加扰,从而产生下面显示的故障.

它发生在我的带有Dalvik运行时的Nexus 5和Android的股票以及我的朋友的带有ART运行时和SlimKat rom的Nexus 4上.但是在具有Dalvik运行时和4.4.2(AOSB rom)的另一个Nexus 5上无法观察到.奇怪的是,在我更新到应用程序的最新版本之前,它没有发生.
下面是使用的布局,其中main_fragment是我Fragment使用事务处理的地方.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/main_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我发现执行此行时会出现故障,并且我在setBackgroundDrawable方法中放置的内容无关紧要:
activity.getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(getCurrentTheme(activity))));
Run Code Online (Sandbox Code Playgroud)
还有人有这个问题吗?或者也许有人知道解决方法或如何使其工作?
编辑:我需要在运行时更改ActionBar颜色(在应用程序设置中更改主题).
user-interface android android-fragments visual-glitch android-actionbar
我开始在Android Studio中使用Robolectric.起初我想用hamcrest创建一个简单的测试,如下所示:
@RunWith(CustomTestRunner.class)
@Config(emulateSdk = 18)
public class MainActivityTest {
private MainActivity mainActivity;
@Test
public void testMainActivity() {
mainActivity = buildActivity(MainActivity.class).create().get();
assertThat(mainActivity, notNullValue());
}
}
Run Code Online (Sandbox Code Playgroud)
执行测试时会抛出以下异常:
java.lang.ClassCastException: java.lang.NoSuchMethodError cannot be cast to java.lang.RuntimeException
at org.robolectric.internal.ReflectionHelpers.callInstanceMethodReflectively(ReflectionHelpers.java:68)
at org.robolectric.util.ActivityController$1.run(ActivityController.java:115)
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:268)
at org.robolectric.util.ActivityController.create(ActivityController.java:111)
at org.robolectric.util.ActivityController.create(ActivityController.java:122)
at com.enprodo.wakemethere.googleservices.geofence.GeofenceTest.testReceiver(GeofenceTest.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:236)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:158) …Run Code Online (Sandbox Code Playgroud) android robolectric android-studio robolectric-gradle-plugin