用Dialog 做自定义动画,加播放监听
final Dialog customDialog = new Dialog(this); customDialog.setTitle(R.string.attention); customDialog.setContentView(R.layout.connectionview); ImageView image = (ImageView)customDialog.findViewById(R.id.anim); image.setBackgroundResource(R.drawable.connection); customDialog.setOnShowListener(new DialogInterface.OnShowListener(){ public void onShow(android.content.DialogInterface dialog){ ImageView image =(ImageView)customDialog.findViewById(R.id.anim); AnimationDrawable ad = (AnimationDrawable)image.getBackground(); if(ad != null) { ad.start(); } } }); customDialog.show(); 这里利用的onShowListener,注意这个接口需要高版本的SDK。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】凌霞软件回馈社区,携手博客园推出1Panel与Halo联合会员
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步