自定义一个View作为弹出对话框
public void dialog(){
//获得布局对象
View view = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_loading, null);
//设置参数等
view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT));
iv = ((ImageView) view.findViewById(R.id.iv_loading));
//开启动画
AnimationDrawable drawable = (AnimationDrawable) iv.getBackground();
drawable.start();
//创建对话框和主题
Dialog loading = new Dialog(getActivity(),R.style.NobackDialog);
//设置是否能点击取消
loading.setCancelable(false);
//把视图加载如对话框
loading.setContentView(view);
loading.show();
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:orientation="vertical"
android:layout_height="wrap_content">
<ImageView
android:background="@drawable/load_animation"
android:id="@+id/iv_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
样式 可让带对话框透明
<color name="no_back">#0fff</color>
<style name="NobackDialog" parent="@android:style/Theme.Dialog">
<item name="android:windowBackground">@color/no_back</item>
</style>