Reputation: 159
Together with friends I have created an Android app and I have a strange issue connected with the UI.
When switching between fragments sometimes the UI tends to scramble, create a glitch displayed below.
It happens on my Nexus 5 with Dalvik runtime and stock Android and on my friend's Nexus 4 with ART runtime and SlimKat rom. But it is not observable on another Nexus 5 with Dalvik runtime and 4.4.2 (AOSB rom). The weird thing is that it was not happening before I updated to the newest version of the app.
Below is the layout used, where the main_fragment
is the place I put the Fragment
with the use of transaction.
<?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>
I found out that the glitch appears when this line is executed and it does not matter what I put inside the setBackgroundDrawable
method:
activity.getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(getCurrentTheme(activity))));
Does anybody else have this problem? Or maybe someone knows a workaround or how to make it work?
Edit: I need to change the ActionBar color in runtime (changing theme in app settings).
Upvotes: 5
Views: 813
Reputation: 4550
I encountered this problem a few days ago when applying a background color to the ActionBar at runtime. This was on a Nexus 5 running stock Android 5.0, and I had success with the workaround suggested in this reply of this issue: Issue 1760
The workaround is to disable Hardware Acceleration either globally or for the particular Activity where this occurs. There is one more possibility, which is to disable hardware acceleration for a View at runtime, but I'm not sure how to apply this to the ActionBar.
AndroidManifest.xml:
<application android:hardwareAccelerated="false" ...>
AndroidManifest.xml:
<application android:hardwareAccelerated="true">
<activity ... />
<activity android:hardwareAccelerated="false" />
</application>
At runtime
myView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
Upvotes: 4