Reputation: 2071
I want to show the custom animation in the dialog instead of regular animation in progress dialog.
Following is my layout XML file:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/blankImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@anim/loading_anim"/>
</LinearLayout>
In onShowListener of Dialog, I called,
dialog.setOnShowListener(new DialogInterface.OnShowListener(){
@Override
public void onShow(DialogInterface dialog) {
final ImageView imageView = (ImageView) dlg.findViewById(R.id.blankImageView);
final AnimationDrawable yourAnimation = (AnimationDrawable) imageView.getBackground();
yourAnimation.start();
}
});
As you can see, I started the animation after dialog in OnShowListener. If i start the animation in any other method such as onStart(), onCreate() method of dialog, animation will not work as AnimationDrawable is not attached to window.
But onShowListener interface is from API level 8. My question is that, Is there any way before API level 8 to know if AnimationDrawable is attached to window?
Upvotes: 0
Views: 6411
Reputation: 2071
I override the onWindowFocusChanged() function and there i started the animation. This function is there since API level 1. So it work like charm for all version
@Override
public void onWindowFocusChanged(boolean hasFocus){
ImageView imageView = (ImageView) findViewById(R.id.blankImageView);
AnimationDrawable yourAnimation = (AnimationDrawable) imageView.getBackground();
yourAnimation.start();
}
Upvotes: 1