2019独角兽企业重金招聘Python工程师标准>>>
本人一直想做个好看的loading框,技术不够,后来看到一个开源控件不错,就用这个控件然后加上自己的想法改成了一个dialog,觉得还不错,分享出来。没有废话,直接开干。
开源库地址:https://github.com/ybq/Android-SpinKit?utm_source=tuicool&utm_medium=referral
项目的build.gradle中:
allprojects {repositories {...maven { url "https://jitpack.io" }}
}
工程项目中的build.gradle中:
compile 'com.github.ybq:Android-SpinKit:1.1.0'
XML:
Java代码:
//各种样式示例(更多样式见原开源库地址)ChasingDots chasingDots = new ChasingDots();DoubleBounce doubleBounce = new DoubleBounce();FoldingCube foldingCube = new FoldingCube();WanderingCubes wanderingCubes = new WanderingCubes();View inflate = LayoutInflater.from(getApplicationContext()).inflate(R.layout.test, null);SpinKitView viewById = (SpinKitView) inflate.findViewById(R.id.spin_kit);viewById.setIndeterminateDrawable(foldingCube);builder = new AlertDialog.Builder(MainActivity.this);//自定义dialog的布局样式builder.setCustomTitle(inflate);alertDialog = builder.create();alertDialog.setCancelable(true);//设置dialog框背景透明Window window = alertDialog.getWindow();WindowManager.LayoutParams lp = window.getAttributes();lp.alpha = 0.7f;window.setAttributes(lp);alertDialog.setCanceledOnTouchOutside(true);alertDialog.show();
效果图(这里只贴了原来的样例图,dialog的效果图差不多,就不贴了):