Android Dialog 大总结 (二)

续上篇,由于微信文章字符限制,故分两篇

  1. 简单对话框

  2. 多选按钮对话框

  3. 单选按钮对话框

  4. 列表对话框

  5. 水平进度条对话框

  6. 圆形进度条对话框

  7. 自定义图文对话框

  8. 自定义输入对话框

  9. 自定义样式对话框

  10. 自定义Loading样式对话框

  11. 继承 DialogFragment 实现对话框

  12. Activity形式的 对话框

如需查看其它Dialog 请查看上篇文章

上篇文章链接

续上篇

9. 自定义样式对话框

  • 实现效果如下:

0?wx_fmt=png

  • 实现代码如下:



        // 对话框和activity绑定,所以必须传递activity对象
        Builder builder = new AlertDialog.Builder(this);
        // 获取对话框对象
        final AlertDialog dialog = builder.create();
        // 修改对话框的样式(布局结构)
        View view = View.inflate(this, R.layout.dialog_custom_style, null);

        // 因为在2.3.3版本上,系统默认设置内间距,所以需要去除此内间距
        // dialog.setView(view);
        dialog.setView(view, 0, 0, 0, 0);

        // 找到对话框中所有控件
        Button bt_submit = (Button) view.findViewById(R.id.bt_submit);
        Button bt_cancel = (Button) view.findViewById(R.id.bt_cancel);

        final EditText et_set_psd = (EditText) view
                .findViewById(R.id.et_set_psd);
        final EditText et_confirm_psd = (EditText) view
                .findViewById(R.id.et_confirm_psd);

        bt_submit.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // 如果用户没有输入两次密码,告知用户输入密码
                String psd = et_set_psd.getText().toString().trim();
                String confirmPsd = et_confirm_psd.getText().toString().trim();
                if (!TextUtils.isEmpty(psd) && !TextUtils.isEmpty(confirmPsd)) {
                    if (psd.equals(confirmPsd)) {
                        // 当前的对话框隐藏
                        dialog.dismiss();

                    } else {
                        Toast.makeText(getApplicationContext(), "两次输入密码不一致",
                                Toast.LENGTH_SHORT).show();
                    }
                } else {
                    Toast.makeText(getApplicationContext(), "密码不能为空",
                            Toast.LENGTH_SHORT).show();
                }
            }
        });

        bt_cancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        // 展示对话框
        dialog.show();    

注意: 1. 自定义样式布局如下:

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

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/holo_blue_light"
        android:gravity="center"
        android:textColor="@android:color/white"
        android:layout_marginBottom="10dp"
        android:padding="10dp"
        android:text="设置密码"
        android:textSize="20sp" />

    <EditText
        android:id="@+id/et_set_psd"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:background="@drawable/edittext_background"
        android:hint="输入密码"
        android:inputType="textPassword"
        android:padding="5dp"
        android:textSize="22sp" />

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_marginBottom="2dp"
        android:layout_marginTop="2dp"
        android:background="@drawable/tittle_bg" />

    <EditText
        android:id="@+id/et_confirm_psd"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:background="@drawable/edittext_background"
        android:hint="确认密码"
        android:inputType="textPassword"
        android:padding="5dp"
        android:textSize="22sp" />

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_marginTop="5dp"
        android:background="@drawable/tittle_bg" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="3dp"
        android:layout_marginTop="3dp"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/bt_submit"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:background="@drawable/selector_btn_normal"
            android:text="确认" >
        </Button>

        <Button
            android:id="@+id/bt_cancel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:background="@drawable/selector_btn_normal"
            android:text="取消" >
        </Button>
    </LinearLayout>

</LinearLayout>

注意 : 2 EditText 的背景是画的圆角矩形

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <!-- 圆角-->
    <corners android:radius="5dp" />
    <!--描边-->
    <stroke
        android:width="1dp"
        android:color="@color/grey" />

</shape>

10. 自定义Loading样式对话框

  • 实现效果如下:

0?wx_fmt=png

  • 实现代码如下:



        LayoutInflater inflater = LayoutInflater.from(this);
        View v = inflater.inflate(R.layout.dialog_custom_style_progress, null);
        LinearLayout layout = (LinearLayout) v.findViewById(R.id.dialog_view);

        ImageView spaceshipImage = (ImageView) v.findViewById(R.id.img);
        TextView tipTextView = (TextView) v.findViewById(R.id.tipTextView);

        Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(this,
                R.anim.loading_animation);

        spaceshipImage.startAnimation(hyperspaceJumpAnimation);

        Dialog loadingDialog = new Dialog(this, R.style.loading_dialog);

        // loadingDialog.setCancelable(true);//“返回键”取消 不可以用
        loadingDialog.setContentView(layout, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT));
        loadingDialog.show();    

注意:1. 自定义样式如下:

> <!-- 自定义loading dialog样式 -->
    <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/loading_bg</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowContentOverlay">@null</item>
    </style>

注意:2. 自定义样式动画如下:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <!-- 自定义旋转的动画 -->
    <rotate
        android:duration="800"
        android:fromDegrees="0"
        android:interpolator="@android:anim/linear_interpolator"
        android:pivotX="50%"
        android:pivotY="50%"
        android:repeatCount="-1"
        android:repeatMode="restart"
        android:startOffset="-1"
        android:toDegrees="+360" />

</set>

注意 3. 自定义样式的布局如下:

<?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="@drawable/loading_bg"
    android:gravity="center"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="20dp"
        android:gravity="center_horizontal"
        android:src="@drawable/loading" />

    <TextView
        android:id="@+id/tipTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginBottom="20dp"
        android:layout_marginTop="10dp"
        android:gravity="center_horizontal"
        android:text="loading..."
        android:textColor="@android:color/holo_green_light"
        android:textSize="20sp" />

</LinearLayout>

11. 继承 DialogFragment 实现对话框

  • 实现效果如下:

0?wx_fmt=png

  • 实现代码如下:

1.自定义继承DialogFragment 类

public class CustomDialogFragment extends DialogFragment {

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
          // Use the Builder class for convenient dialog construction
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setMessage("通过 DialogFragment 创建对话框")
               .setTitle("DialogFragment")
               .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                      Toast.makeText(getActivity(), "点击 OK", Toast.LENGTH_SHORT).show(); 
                   }
               })
               .setNegativeButton("cancle", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       // User cancelled the dialog
                   }
               });
        // Create the AlertDialog object and return it
        return builder.create();
    }
}
  1. Activity 调用显示Dialog方法

CustomDialogFragment  customDialogFragment=new CustomDialogFragment();
        customDialogFragment.show(getFragmentManager(), "fragment");

12. Activity形式的 对话框

只需创建一个 Activity,并在 <activity> 清单文件元素中将其主题设置为 Theme.Holo.Dialog:

<activity android:theme="@android:style/Theme.Holo.Dialog" >

至此,Dialog 相关的知识点已结束。

欢迎关注微信公众号:程序员Android

微信公众号:ProgramAndroid

我们不是牛逼的程序员,我们只是程序开发中的垫脚石。

0?wx_fmt=gif

点击阅读原文,获取更多福利

0?wx_fmt=gif

内容概要:本文介绍了ENVI Deep Learning V1.0的操作教程,重点讲解了如何利用ENVI软件进行深度学习模型的训练应用,以实现遥感图像中特定目标(如集装箱)的自动提取。教程涵盖了从数据准备、标签图像创建、模型初始化训练,到执行分类及结果优化的完整流程,并介绍了精度评价通过ENVI Modeler实现一键化建模的方法。系统基于TensorFlow框架,采用ENVINet5(U-Net变体)架构,支持通过点、线、面ROI或分类图生成标签数据,适用于多/高光谱影像的单一类别特征提取。; 适合人群:具备遥感图像处理基础,熟悉ENVI软件操作,从事地理信息、测绘、环境监测等相关领域的技术人员或研究人员,尤其是希望将深度学习技术应用于遥感目标识别的初学者实践者。; 使用场景及目标:①在遥感影像中自动识别和提取特定地物目标(如车辆、建筑、道路、集装箱等);②掌握ENVI环境下深度学习模型的训练流程关键参数设置(如Patch Size、Epochs、Class Weight等);③通过模型调优结果反馈提升分类精度,实现高效自动化信息提取。; 阅读建议:建议结合实际遥感项目边学边练,重点关注标签数据制作、模型参数配置结果后处理环节,充分利用ENVI Modeler进行自动化建模参数优化,同时注意软硬件环境(特别是NVIDIA GPU)的配置要求以保障训练效率。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值