android 自定义Dialog页面加载中效果的进度条 Dialog 边角 Dialog 棱角

时间:2023-02-09 09:16:08

android 自定义Dialog页面加载中效果的进度条  Dialog 边角 Dialog 棱角


        android 自定义Dialog页面加载中效果的进度条  Dialog 边角 Dialog 棱角 android 自定义Dialog页面加载中效果的进度条  Dialog 边角 Dialog 棱角

Dialog 边角 Dialog 棱角

<style name="loading_dialog" parent="android:Theme.Dialog">
<item name="android:windowFrame">@null</item>
<!-- Dialog的windowFrame框为无 -->
<item name="android:windowBackground">@color/transparent</item>
<!-- 设置dialog的背景 -->
<item name="android:windowNoTitle">true</item>
<!-- 是否显示title -->
<item name="android:windowIsTranslucent">true</item>
<!-- 是否半透明 -->
<item name="android:windowIsFloating">true</item>
<!-- 是否浮现在activity之上 -->
<item name="android:windowContentOverlay">@null</item>
<!-- 也是个drawable,定义contentoverlay的背景 -->
<item name="android:backgroundDimEnabled">false</item>
<!-- 背景是否模糊显示 -->
</style>

Dialog loadingDialog = new Dialog(context, R.style.loading_dialog); // 创建自定义样式dialog
loadingDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

加载数据时调用的方法:

LodingDialog dialog = new LodingDialog(this);

dialog.show();// 显示加载条

dialog.dismiss();// 关闭加载进度条


LodingDialog.java

public class LodingDialog extends Dialog {

private Context context;
private ImageView imagLoading;
private Animation operatingAnim;

public LodingDialog(Context context) {
super(context, R.style.loading_dialog);
this.context = context;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.loading);
imagLoading = (ImageView)findViewById(R.id.loading);
operatingAnim = AnimationUtils.loadAnimation(context, R.anim.cirle);
LinearInterpolator lin = new LinearInterpolator();
operatingAnim.setInterpolator(lin);

imagLoading.startAnimation(operatingAnim);
}

@Override
public void show() {
// TODO Auto-generated method stub
if (imagLoading != null) {
imagLoading.startAnimation(operatingAnim);
}
super.show();
}

@Override
public void dismiss() {
// TODO Auto-generated method stub
if (imagLoading != null) {
imagLoading.clearAnimation();
}
super.dismiss();
}

@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction()==MotionEvent.ACTION_MOVE) {
dismiss();
return true;
}
return super.onTouchEvent(event);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
dismiss();
return true;
}
return super.onKeyDown(keyCode, event);
}

}

styles.xml   样式切忌不可忘记

<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">@drawable/transpant_bg</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:backgroundDimEnabled">false</item>
</style>

loading.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00ffffff"
android:orientation="vertical"
android:gravity="center">

<ImageView
android:id="@+id/loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/yj_refresh"/> <!-- 就是你要的加载图片 -->

</RelativeLayout>

到此就算是dialog加载进度条就算完成了...