自定义dialog,具体需求可以具体扩展

干货,关于自定义Dialog的宽度充满屏幕的方法以及为什么设置失败(扩展:自定义Dialog形状) 为了让自定义dialog的宽度充满屏幕,可能会在网上搜了各种各样的方法来实现这一目的,可能都失败了,这是为什么呢?因为自定义布局加载的位置不对,直接看图: 因为是在代码里面设置的dialog宽度全屏,而不是在styles里面,所以不能在创建dialog的时候加载自定义的布局,怎么实现Dialog的宽度全屏?为了清晰明了,贴图: 为了让dialog宽度全屏,在你dialog.sh 阅读详情

1.样式如下,简单易用,如果需要其他样式,直接更改样式就行。

 

2.自定义代码实现方式:

/**
* 支付方式单选对话框
* Created by J.query on 16/4/9.
*/

public class PaySelectDialog extends android.app.Dialog {

 

  private Context mContext;
    private TextView mTitleTv;
    private TextView mRightTv;
    private TextView mLeftTv;
    private ImageView mCloseIv;
    private LinearLayout mLlRightTv;
    private LinearLayout mLlLeftTv;

    public PaySelectDialog(Context context) {
        this(context, false);
    }

    /**
     * @param context
     * @param b       是否隐藏right btn
     */
    public PaySelectDialog(Context context, boolean b) {
        this(context, R.style.SelectDialog);
        this.mContext = context;
        initViews(b);
    }

    public PaySelectDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    private void initViews(boolean b) {
        LayoutInflater layoutInflater = LayoutInflater.from(mContext);
        View view = layoutInflater.inflate(R.layout.layout_dialog_pay_select, null);
        mTitleTv = (TextView) view.findViewById(R.id.tv_title);
        View mLine = view.findViewById(R.id.line);
        mRightTv = (TextView) view.findViewById(R.id.tv_right);
        mLeftTv = (TextView) view.findViewById(R.id.tv_left);
        mCloseIv = (ImageView) view.findViewById(R.id.iv_close);
        mLlRightTv = (LinearLayout) view.findViewById(R.id.ll_tv_right);
        mLlLeftTv = (LinearLayout) view.findViewById(R.id.ll_tv_left);
        if (b) {
            mLine.setVisibility(View.GONE);
            mRightTv.setVisibility(View.GONE);
            //leftTv.setBackgroundResource(R.drawable.actionsheet_bottom_selector);
        }

        mLlLeftTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (listener != null)
                    listener.wxClick();
            }
        });
        mLlRightTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (listener != null)
                    listener.otherClick();
            }
        });
        mCloseIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (listener != null)
                    listener.closeClick();
            }
        });
        setContentView(view);

        /**
         * 设置宽度全屏,要设置在show的后面
         */
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.gravity = Gravity.BOTTOM;
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        getWindow().setAttributes(layoutParams);
        getWindow().setGravity(Gravity.BOTTOM);
    }

    /**
     * Title 设置
     * @param s
     * @return
     */
    public PaySelectDialog setTitle(String s) {
        if (mTitleTv != null)
            mTitleTv.setText(s);
        return this;
    }

    public void setLeftAndRightButtonText(String left, String right) {
        if (mLeftTv != null) {
            mLeftTv.setText(left);
        }
        if (mRightTv != null) {
            mRightTv.setText(right);
        }
    }

    /**
     * 设置button 选项值
     * @param left
     * @param right
     */
    public void setLeftAndRightText(String left, String right) {
        if (mLeftTv != null) {
            mLeftTv.setVisibility(View.VISIBLE);
            mLeftTv.setText(left);
        }
        if (mRightTv != null) {
            mRightTv.setVisibility(View.VISIBLE);
            mRightTv.setText(right);
        }
    }

    public void showDialog() {
        if (!isShowing()) {
            show();
        }
    }

    public PaySelectDialogListener listener;

    public PaySelectDialog setListener(PaySelectDialogListener listener) {
        this.listener = listener;
        return this;
    }
}

3.布局文件:

<?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="wrap_content"
    android:background="@drawable/bg_white_2_bg"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center">

        <ImageView
            android:id="@+id/iv_close"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="@dimen/dp_15"
            android:padding="@dimen/dp_10"
            android:src="@drawable/close" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:gravity="center"
            android:padding="@dimen/dp_14"
            android:text="@string/payment"
            android:textColor="@color/c_33"
            android:textSize="@dimen/dp_17"
            android:textStyle="bold" />

    </RelativeLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="@dimen/dp_1"
        android:background="@color/c_da" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center">

        <TextView
            android:id="@+id/tv_pay_dollar_symbol"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/dp_10"
            android:layout_marginTop="@dimen/dp_10"
            android:gravity="center_horizontal"
            android:text="@string/pay_dollar_symbol"
            android:textColor="@color/c_55"
            android:textSize="@dimen/dp_19" />

        <TextView
            android:id="@+id/tv_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/dp_10"
            android:layout_marginLeft="@dimen/dp_7"
            android:layout_toRightOf="@id/tv_pay_dollar_symbol"
            android:text="111"
            android:textColor="@color/c_55"
            android:textSize="@dimen/dp_29" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/dp_10"
        android:layout_marginTop="@dimen/dp_10"
        android:background="@color/c_f8">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/dp_20"
            android:padding="@dimen/dp_8"
            android:text="@string/payment_method"
            android:textColor="@color/c_66"
            android:textSize="16dp" />
    </RelativeLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/dp_20"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/ll_tv_left"
            style="@style/button_white_frame"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/dp_80"
            android:layout_marginRight="@dimen/dp_80"
            android:gravity="center"
            android:orientation="horizontal"
            android:padding="@dimen/dp_10">

            <TextView
                android:id="@+id/tv_left"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:drawableLeft="@drawable/wx_logo"
                android:drawablePadding="@dimen/dp_10"
                android:gravity="center"
                android:text="@string/wx_pay"
                android:textColor="@color/c_33"
                android:textSize="@dimen/dp_15" />
        </LinearLayout>

        <View
            android:id="@+id/line"
            style="@style/vertical_line"
            android:visibility="gone" />

        <LinearLayout
            android:id="@+id/ll_tv_right"
            style="@style/button_white_frame"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/dp_80"
            android:layout_marginRight="@dimen/dp_80"
            android:layout_marginTop="@dimen/dp_15"
            android:gravity="center"
            android:orientation="vertical"
            android:padding="@dimen/dp_10">

            <TextView
                android:id="@+id/tv_right"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:drawableLeft="@drawable/cash_payment"
                android:drawablePadding="@dimen/dp_10"
                android:gravity="center"
                android:text="@string/cash_pay"
                android:textColor="@color/c_33"
                android:textSize="@dimen/dp_15" />
        </LinearLayout>
    </LinearLayout>


</LinearLayout>

styles  文件

<style name="button_white_frame">
    <item name="android:gravity">center</item>
    <item name="android:background">@drawable/button_rounded_white_frame</item>
    <item name="android:textColor">@drawable/button_white_text</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textSize">16sp</item>
</style>

button_rounded_white_frame.xml      文件

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

    <item android:state_focused="false" android:state_pressed="false" android:state_enabled="true" android:drawable="@drawable/frame_rounded_white" />
    <item android:state_enabled="false" android:drawable="@drawable/frame_rounded_white" />
    <item android:state_pressed="true" android:drawable="@drawable/frame_rounded_white_pressed" />
    <item android:state_focused="true" android:drawable="@drawable/frame_rounded_white_pressed" />
</selector>
button_white_text.xml 文件

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

    <item android:color="@color/c_ff" android:state_enabled="true" android:state_focused="false" android:state_pressed="false" />
    <item android:color="@color/c_ff" android:state_enabled="false" />
    <item android:color="@color/c_ff" android:state_pressed="true" />
    <item android:color="@color/c_ff" android:state_focused="true" />

</selector>

4.示例代码:

/**
* 选择支付选项值
*
* @param pay
* @param amount
* @param pay
*/
public void showSelectDialog(final String pay, final String amount) {
    if (mPaySelectDialog == null) {
        mPaySelectDialog = new PaySelectDialog(this, true);
        mPaySelectDialog.setListener(new PaySelectDialogListener() {
            @Override
            public void wxClick() {
                initWeChatPayQrData(pay, amount);
            }

            @Override
            public void otherClick() {
                initCashPaymentData(pay, amount, mReWriteFlag);
            }

            @Override
            public void closeClick() {
                //dialog.dismiss();
            }
        });
        mPaySelectDialog.setTitle(pay);
        mPaySelectDialog.setCanceledOnTouchOutside(false);
        mPaySelectDialog.setCancelable(false);
        mPaySelectDialog.setLeftAndRightText(getString(R.string.wx_pay), getString(R.string.cash_pay));
    } else {
        mPaySelectDialog.setListener(new PaySelectDialogListener() {
            @Override
            public void wxClick() {
                initWeChatPayQrData(pay, amount);
            }

            @Override
            public void otherClick() {
                initCashPaymentData(pay, amount, mReWriteFlag);
            }

            @Override
            public void closeClick() {
                //dialog.dismiss();
            }
        });
        mPaySelectDialog.setTitle(pay);
        mPaySelectDialog.setCanceledOnTouchOutside(false);
        mPaySelectDialog.setCancelable(false);
        mPaySelectDialog.setLeftAndRightText(getString(R.string.wx_pay), getString(R.string.cash_pay));
    }
    mPaySelectDialog.showDialog();
}

安卓下Builder模式解析+自定义Dialog实战演练 **本文将从一下几个方面展开: 1Bulider模式的原理和使用 2系统Dailog的调用 3自定义Dailog 4自定义Dailog的一些小坑**本文Github代码链接 https://github.com/AndroidMsky/AirDialog自定义Dailog效果: 1Bulider模式的原理和使用当你看到这样的一串代码是不是觉得很炫酷? airDialog = new A 阅读详情

相关推荐

自定义Dialog Theme的Activity

##背景 最近公司开发NFC开门的功能,咋一眼看功能很简单,直接用Dialog方式封装就能解决问题。但是我们公司是模块化的方式搭建开发App,为了让模块间的代码层次清晰与扩展及易与阅读,因此我们最终用Activity的方式实现Dialog的样式及功能。 以下的开发过程以dialog1图片举例说明 ##开发过程 ###1.创建Theme样式 <style name="activityT...

龚十一 2372

vue+elementui扩展dialog可拖拽

利用Vue的钩子函数扩展 elementui中的dialog可拖拽 Vue.directive('dialogDrag',{ bind(el,binding,vnode,oldVnode){ constdialogHeaderEl=el.querySelector('.el-dialog__header'); constdragDom=el.querySelector('.el-dialog'); //dialogHeader...

MLAY 294

[扩展]EasyUI给dialog的buttons绑定click事件

通常,Dialog中的Buttons的Click是在生成的时候就通过如下方式写好的。 官网的代码 <div id="dialog" class="easyui-dialog" data-options="title:'My Dialog',modal:true, buttons:[{ text:'Save',

我是涛锅 1万+

自定义Dialog

一些类库: https://github.com/qiushi123/CustomDialog https://github.com/jiang111/IndicatorDialog https://github.com/fython/MaterialPreferenceCompat loading效果 https://github.com/d-max/spots-dialog lic

Lambert_A的博客 818

扩展jQuery UI Dialog组件的详细指南

jQuery UI是一个成熟的JavaScript库,它在jQuery的基础上扩展了用户界面交互功能。Dialog组件是其中的交互元素之一,允许开发者快速创建可用于显示信息、创建模态对话框等的弹出窗口。使用Dialog组件能够创建具有多种交互功能的模态或非模态对话框,并支持自定义样式和行为。jQuery UI Dialog组件拥有丰富的默认设置,这些设置构成了其基础行为和外观。了解这些默认属性和方法是定制Dialog之前的基础。默认属性包括但不限于:autoOpen。

weixin_32252929的博客 1092

Android自定义Dialog无边框实现教程

本文还有配套的精品资源,点击获取 简介:本教程将介绍如何在Android开发中自定义Dialog类,去除其默认边框,使其更融入应用界面。首先通过继承 AppCompatDialog 或 AlertDialog 创建自定义Dialog类,并通过设置自定义布局及主题来去除边框。教程中还包括如何通过XML布局文件来设计Dialog内容,并在自定义Dia...

weixin_42576804的博客 1697

Android/安卓 自定义Dialog 最简单、最详细解释

全网最简明的自定义Dialog

Chyumin的博客 1万+

Android自定义Dialog任意位置显示实战

在Android开发中,Dialog默认居中显示,难以满足如气泡提示、锚点弹窗等复杂UI需求。为实现精准定位,需深入理解中的gravityxy等参数,并结合屏幕坐标系动态计算位置。通过继承,可灵活控制窗口属性,突破系统默认布局限制,为后续实现类PopupWindow效果奠定基础。在Android开发中,Dialog是一种常见的模态交互组件,广泛用于提示、确认、输入等场景。然而,系统默认的或基础Dialog往往只能居中显示,难以满足复杂界面布局中的定位需求。

weixin_42578963的博客 1394

Flutter中自定义Dialog

Dialog在不同的平台,都是一种重要的交互方式,在Flutter中,Dialog也是有很多种,但大多数场景的交互,都需要根据项目的主题或一些特定的交互去实现自定义的Dialog。

程序员吗? 1538

创建自定义Android Dialog的设计与实现

Android Dialog是用于在当前屏幕显示信息并获取用户输入的一个轻量级的窗口。它是UI组件的一部分,用于创建模态对话框,可以覆盖在其他界面元素之上,要求用户先处理,才能返回到原始界面。设计自定义Dialog的首要步骤是深入理解应用中的用户界面需求。这涉及到用户与应用程序交互时的期望,以及对话框在这些场景中需要完成的任务。用户界面需求应当简洁明了,对话框应该只包含完成特定任务所需的最少信息。例如,在表单提交失败时,对话框应仅提供错误信息和必要的重试或取消选项。

weixin_33363025的博客 1015

Android自定义dialog对话框

仿新浪微博的对话框,非常简洁漂亮自定义的dialog,纯代码编写,已封装好,将关键的代码拷进项目即可使用。

Android自定义的Dialog,[Android]自定义万能Dialog

在我们开发Android项目的时候,难免需要制作各式各样的Dialog,例如: 假如是使用Android自带的dialog比较难实现这样的效果,不过,我们也可以依照这篇文章所述来自定义自己喜欢的dialog:[Android]自定义Dialog。但是,这样就出现了一个问题,假如我们每一个Dialog都需要如此的自定义一个类,那样代码的冗余性就很高了,明明很多可以重用的代码却只能依靠复制...

weixin_30393633的博客 943

Android对话框库(PopupWindow Dialog等)

一个强大的Android对话框库,简化自定义对话框.支持2.2+. 内置Dialog,方便直接使用 丰富的内置动画库,方便直接使用 支持快速自定义Dialog 支持快速自定义Popup 支持自定义Dialog动画 git 相关链接 https://github.com/H07000223/FlycoDialog_Master/blob/master/README_CN.md apk 地址 https://fir.im/mj9p

Android自定义Dialog

在项目中我们经常需要使用Dialog弹出一些信息告知用户或者指引用户做一些选择性操作。 Android系统提供了Dialog类,以及Dialog的子类,常见如AlertDialog来实现此类功能。但是不足之处有以下几点: 1. 基于Android提供的Dialog及其子类样式单一,风格上与App本身风格可能不太协调; 2. Dialog弹窗在布局和功能上有所限制,不一定能满足实际的业务需求。

戴戴的博客 724

VB6.0 自定义Dialog打开文件对话框.rar

VB6.0 自定义对话框,自定义Dialog对话框。成功之后你会发现,打开文件,文件夹对话框的控件 ,有新建文件夹按钮,还有其他的一些附加功能。里面用到了自定义的VB类库。代码中的注释是英文的,本对话框运行效果如图所示。

PCB设计必看:铜皮厚度与载流能力对照表(附Excel计算工具)

本文深入解析了PCB设计中铜皮厚度与载流能力的核心关系,提供了基于IPC-2152标准的动态计算逻辑与实用Excel工具。文章不仅分享了载流对照表,更重点剖析了影响载流能力的关键因素(如铜厚、线宽、温升、布线层),并给出了高电流设计的实战技巧与测试验证方法,帮助工程师规避常见陷阱,实现从理论到实践的闭环设计。

weixin_29228781的博客 729

Android 自定义布局的dialog宽高变形问题

这几天在做自定义布局的dialog时,踩了不少的坑,现在记录下自认为最大的坑。 首先,我们来创建一个定义dialog布局的xml文件。dlg_test.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/andr...

残风乱了温柔的博客 3252

TVS 管击穿电压与钳位电压的工程解析

TVS二极管的核心参数击穿电压(VBR)和钳位电压(VC)常被混淆,但二者具有本质区别。VBR是

硬核科技 482

全屏Dialog实现,布局可扩展到状态栏和导航栏

话不多说一看就懂,网上的大部分实现都没效果,用这个就对了 public class FullScreenDialog extends Dialog { private View view; public FullScreenDialog(@NonNull Context context, View view) { super(context); this.view = view; } public FullScreenDialog(@N

ForgetSky的博客 7418

SAP S/4HANA Public Cloud 配置全景实践

本文提供SAP S/4HANA Public Cloud配置的实用指南,重点介绍三大核心工具:CBC(范围界定与配置)、SAP Activate(方法论与路线图)和Cloud ALM(项目执行与运维)。文章详解了不同系统架构(2SL/3SL)的配置路径,并以制造企业案例说明端到端实施流程。同时提供了工具协同操作方法、初始访问安全建议和常见问题的专家意见,帮助项目团队高效完成实施工作。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 566

汽车安全新防线|基于AI的入侵检测系统开发(全网独家复现),CNN-BiLSTM融合改进篇 强化CAN总线数据感知、助力多类型入侵检测、实时响应预警、车载场景有效落地

基于AI的入侵检测系统是汽车网络安全领域的重要技术突破,能够有效应对日益复杂的网络攻击威胁。随着AI技术的不断发展和普及,AI入侵检测系统将在汽车安全领域发挥越来越重要的作用。对于汽车制造商和供应商来说,实施AI入侵检测系统不仅是保障车辆安全的需要,也是提升市场竞争力的重要手段。未来,AI入侵检测系统将成为智能汽车的标准配置,为用户提供更加安全、可靠的驾驶体验。

getusushu的博客 86
上一篇: 自定义(标题栏)TitleBar样式
下一篇: Android Studio 报错显示 mips64el-linux-android-strip 找不到
J-query
博客等级 码龄10年 248粉丝 39原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值