start_background.xml
<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@color/grey"
android:maxLevel="1"
/>
<item
android:drawable="@color/grey"
android:maxLevel="2"
/>
<item
android:drawable="@color/grey"
android:maxLevel="3"
/>
</level-list>
start_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/page"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/start_background"
android:id="@+id/start"
/>
</LinearLayout>
Java Code
ImageView image= (ImageView)findViewById(R.id.start);
LevelListDrawable background=(LevelListDrawable)image.getBackground();
background.setLevel(3);
but it can not change the background, I have try to change android:background to android:src, it didn't work also.
logcat:
2690-2705/com.jifa.runandcatch2 W/EGL_emulation﹕ eglSurfaceAttrib not implemented
2690-2705/com.jifa.runandcatch2 W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xae0e1de0, error=EGL_SUCCESS
how to solve it, thanks.
Use:
image.setImageLevel(3);
instead than:
LevelListDrawable background=(LevelListDrawable)image.getBackground(); background.setLevel(3);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With