资料阅读
了解dialog的类别和使用
http://www.cnblogs.com/xiaoluo501395377/p/3419398.html
http://www.cnblogs.com/xiaoluo501395377/p/3421727.html
实现一个自定义的dialog
https://blog.csdn.net/Small_Lee/article/details/50602400
https://blog.csdn.net/small_lee/article/details/50602500
progressBar和progressDialog的使用
https://blog.csdn.net/hardworkingant/article/details/71910731
新版本谷歌推荐用dialogFragment来替代dialog和相关的子类,能更好的管理窗口的生命周期以及在屏幕切换的时候,及时的保存数据
资料参考 https://blog.csdn.net/xiangzhihong8/article/details/38294059
小实践:设置一个浮空的progressBar(DialogFragment)
布局文件
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_remind"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:text="@string/wait_please_qsh"
app:layout_constraintBottom_toBottomOf="@+id/progressBar"
app:layout_constraintEnd_toStartOf="@+id/progressBar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/progressBar" />
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:indeterminate="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
dialogFragment
重写oncancle()和onDismiss()
public class ProgressBarFragment extends DialogFragment {
private static final String TAG = "LogUtil.ProgressBarFt";
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.progress_bar_no_click,container);
}
@Override
public void onCancel(DialogInterface dialog) {
LogUtil.i(TAG, "onCancel: ");
super.onCancel(dialog);
}
@Override
public void onDismiss(DialogInterface dialog) {
LogUtil.i(TAG, "onDismiss: ");
super.onDismiss(dialog);
}
}
调用
ProgressBarFragment progressBar=new ProgressBarFragment();
progressBar.show(getSupportFragmentManager(),"inquireCustomDuplicate");
实现效果
填坑:
1,怎么设置diolog的宽度
//获得屏幕的实例
Display d=getWindowManager().getDefaultDisplay();
//获得窗体的属性
WindowManager.LayoutParams lp = dialogWindow.getAttributes();
//设置Dialog距离底部的距离
lp.y = 20;
//设置diolog的宽度位屏幕宽度
Point point=new Point();
d.getSize(point);
lp.width=point.x;
//将属性设置给窗体
dialogWindow.setAttributes(lp);
获取屏幕宽度
可以通过Point=d.getSize(),point.x和point.y就是屏幕的宽度和高度
也可以直接通过安卓内置的参数
LayoutParams.match_Parent或者LayoutParams.wrap_content.
https://blog.csdn.net/liuhaomatou/article/details/22899925/
2.设置一个AlertDialog
AlertDialog.Builder builder=new AlertDialog.Builder(getContext());
builder.setMessage("确定退出吗");
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getContext(), "确定退出", Toast.LENGTH_SHORT).show();
OkHttp3Utils.sendHttpLoginOutRequest(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (response.isSuccessful()){
String strResponse=response.body().string();
LogU.i(TAG, "onResponse: response="+strResponse);
System.exit(0);
}
}
});
}
});
builder.setNegativeButton("取消", null);
builder.show();
参考如何通过dialog退出程序
https://www.jb51.net/article/79128.htm