这篇文章主要为大家详细介绍了Android自定义仿ios加载弹窗,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了Android自定义仿ios加载弹窗的具体代码,供大家参考,具体内容如下
效果如下:
IosLoadDialog类(可直接复制):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | public class IosLoadDialog extends Dialog {
public IosLoadDialog(Context context) {
super (context, R.style.loading_dialog);
initView();
}
@Override
public boolean onKeyDown( int keyCode, KeyEvent event) {
switch (keyCode){
case KeyEvent.KEYCODE_BACK:
if (IosLoadDialog. this .isShowing())
IosLoadDialog. this .dismiss();
break ;
}
return true ;
}
private void initView(){
setContentView(R.layout.dialog_loading);
Animation animation = AnimationUtils.loadAnimation(getContext(), R.anim.load_animation);
animation.setInterpolator( new LinearInterpolator());
findViewById(R.id.loading_dialog_img).startAnimation(animation);
setCanceledOnTouchOutside( true );
WindowManager.LayoutParams attributes = getWindow().getAttributes();
attributes.alpha= 0 .8f;
getWindow().setAttributes(attributes);
setCancelable( false );
}
}
|
R.layout.dialog_loading文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | <? xml version = "1.0" encoding = "utf-8" ?>
< LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:id = "@+id/dialog_view"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:background = "@color/tm"
android:gravity = "center"
android:minHeight = "60dp"
android:minWidth = "180dp"
android:orientation = "vertical"
android:padding = "10dp" >
< LinearLayout
android:layout_width = "80dp"
android:layout_height = "80dp"
android:background = "@drawable/white_radian13"
android:gravity = "center"
android:orientation = "vertical" >
< ImageView
android:id = "@+id/loading_dialog_img"
android:layout_width = "50dp"
android:layout_height = "50dp"
android:scaleType = "fitXY"
android:src = "@drawable/ic_svstatus_loading" />
</ LinearLayout >
</ LinearLayout >
|
loading_dialog样式:
1 2 3 4 5 6 7 | < style name = "loading_dialog" parent = "android:style/Theme.Dialog" >
< item name = "android:windowFrame" >@null</ item >
< item name = "android:windowNoTitle" >true</ item >
< item name = "android:windowBackground" >@color/tm</ item >
< item name = "android:windowIsFloating" >true</ item >
< item name = "android:windowContentOverlay" >@null</ item >
</ style >
|
white_radian13白色透明圆角背景:
1 2 3 4 5 6 7 8 9 | <? xml version = "1.0" encoding = "utf-8" ?>
< layer-list xmlns:android = "http://schemas.android.com/apk/res/android" >
< item >
< shape >
< solid android:color = "#F7FBFD" />
< corners android:radius = "13dp" />
</ shape >
</ item >
</ layer-list >
|
然后奉上图片ic_svstatus_loading.png:
最后使用:
1 2 3 4 5 6 7 8 9 10 | public void showDialog(){
final IosLoadDialog iosLoadDialog = new IosLoadDialog( this );
iosLoadDialog.show();
new Handler().postDelayed( new Runnable() {
@Override
public void run() {
iosLoadDialog.dismiss();
}
}, 1200 );
}
|
好了,去试试吧!
0评论