自定义Dialog

内容部分是个listview
在这里插入图片描述
1创建Dialog

 private void getJobTitleDialog() {

        View dialogView = getLayoutInflater().inflate(R.layout.dialog_view, null);
        lvJobTitle = (ListView) dialogView.findViewById(R.id.lv_job_title);
        if(records!=null){
            lvJobTitle.setAdapter(new MyAdapter(records,this));
        }

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        TextView title = new TextView(this);
        title.setTextSize(20);
        title.setTextColor(Color.BLACK);
        title.setGravity(Gravity.CENTER);
        title.setText("职务");
        builder.setCustomTitle(title)
                .setView(dialogView)
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Log.e("wy", "onClick: 点击了确定" );
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Log.e("wy", "onClick: 点击了取消" );
                    }
                })
                .create()
                .show();

    }

2 dialog_view

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="391dp"
    android:layout_height="695dp"
    android:orientation="vertical"
    >
    <TextView
        android:background="@color/stroke_grey"
        android:layout_width="match_parent"
        android:layout_height="1dp"/>
    <ListView
        android:id="@+id/lv_job_title"
        android:divider="@null"
        android:layout_width="match_parent"
        android:layout_height="200dp"/>

</LinearLayout>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Android自定义dialog是一种可以根据开发者的需求进行自定义的对话框。通过自定义dialog,开发者可以实现特定的界面设计和功能。根据引用,我们可以使用AlertDialog.Builder来创建一个普通的弹出框。而根据引用,我们可以通过简单的设置和技巧来实现Android自定义dialog。如果想要对话框具有自定义布局,可以创建一个布局文件,然后通过调用AlertDialog.Builder的setView()方法将其添加到对话框中。默认情况下,自定义布局会填充对话框窗口,但是仍然可以使用AlertDialog.Builder的其他方法来添加按钮和标题。此外,开发者还可以完全自定义一个Dialog,需要进行以下几步: 1. 定义一个style 2. 创建一个继承自Dialog的子类 3. 在子类中实现自定义布局和相关功能 4. 在应用中调用自定义dialog的实例来显示对话框。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [android之自定义Dialog](https://blog.csdn.net/weixin_41796401/article/details/96636408)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [Android自定义dialog简单实现方法](https://download.csdn.net/download/weixin_38736562/12800768)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值