iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >android如何自定义对话框
  • 172
分享到

android如何自定义对话框

2023-06-22 06:06:37 172人浏览 薄情痞子
摘要

这篇文章给大家分享的是有关Android如何自定义对话框的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。实现效果  定义dialog.xml (res/layout/dialog.xml)<

这篇文章给大家分享的是有关Android如何自定义对话框的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

实现效果

  android如何自定义对话框

定义dialog.xml (res/layout/dialog.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:orientation="vertical" >     <RelativeLayout        android:layout_width="250sp"        android:layout_height="270sp"        android:layout_centerInParent="true">         <TextView            android:id="@+id/dialog_title"            android:layout_width="wrap_content"            android:layout_height="35sp"            android:layout_alignParentTop="true"            android:layout_centerHorizontal="true"            android:layout_marginTop="15sp"            android:textColor="#333333"            android:textSize="17sp" />         <TextView            android:id="@+id/dialog_message"            android:layout_width="wrap_content"            android:layout_height="160sp"            android:layout_centerInParent="true"            android:layout_marginTop="65sp"            android:textColor="#333333"            android:textSize="17sp" />         <LinearLayout            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_alignParentBottom="true"            android:layout_centerHorizontal="true"            android:layout_marginTop="30sp"            android:layout_marginBottom="20sp"            android:orientation="horizontal">             <LinearLayout                android:id="@+id/dialog_confirm"                android:layout_width="wrap_content"                android:layout_height="wrap_content">                 <TextView                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:background="@drawable/confirm_button_style"                    android:gravity="center"                    android:text="确定"                    android:textColor="@color/white"                    android:textSize="18sp" />            </LinearLayout>             <LinearLayout                android:id="@+id/dialog_cancel"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_marginLeft="22sp">                 <TextView                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:background="@drawable/cancel_button_style"                    android:gravity="center"                    android:text="取消"                    android:textColor="@color/teal_200"                    android:textSize="18sp" />            </LinearLayout>        </LinearLayout>     </RelativeLayout></RelativeLayout>

设置确定、取消按钮的background

上文的dialog.xml中,确定和取消按钮都是TextView,所以需要自定义按钮的背景

confirm_button_style.xml  (所有的color需要自定义)

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="rectangle">    <corners android:radius="1000sp"/>    <solid android:color="@color/teal_200"/>    <stroke        android:width="0.5sp"        android:color="@color/colorAccent"/>    <size android:width="105sp" android:height="40sp"/></shape>

cancel_button_style.xml 

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="rectangle">    <corners android:radius="1000sp"/>    <solid android:color="@color/white"/>    <stroke        android:width="0.5sp"        android:color="@color/teal_200"/>    <size android:width="105sp" android:height="40sp"/></shape>

自定义dialog的使用

final AlertDialog dialog = new AlertDialog.Builder(xxxClass.this).create();dialog.setCancelable(false); //点击对话框以外的位置,不消失dialog.show(); Window window = dialog.getWindow();window.setContentView(R.layout.dialog);//标题TextView title = window.findViewById(R.id.dialog_title);title.setText("dialog_title"); //内容TextView message = window.findViewById(R.id.dialog_message);message.setText("dialog_message "); //确定按钮LinearLayout confirm = window.findViewById(R.id.dialog_confirm);confirm.setOnClickListener(new View.OnClickListener() {    @Override    public void onClick(View v) {        //xxx    }}); //取消按钮LinearLayout cancel = window.findViewById(R.id.dialog_cancel);cancel.setOnClickListener(new View.OnClickListener() {    @Override    public void onClick(View v) {        //xxx    }});

感谢各位的阅读!关于“android如何自定义对话框”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

--结束END--

本文标题: android如何自定义对话框

本文链接: https://www.lsjlt.com/news/303137.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • android如何自定义对话框
    这篇文章给大家分享的是有关android如何自定义对话框的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。实现效果  定义dialog.xml (res/layout/dialog.xml)<...
    99+
    2023-06-22
  • Android中如何自定义对话框
    本文小编为大家详细介绍“Android中如何自定义对话框”,内容详细,步骤清晰,细节处理妥当,希望这篇“Android中如何自定义对话框”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。本文测试的harbor的版本是...
    99+
    2023-06-29
  • Android如何自定义输入文本对话框?
    文章目录 0.引言1.创建示例工程2.输入文本对话框布局和功能设计3.主程序调用输入文本对话框 0.引言   笔者研究的课题涉及到安卓软件开发,在开发过程中,发现普通的显示消息对话框一般可...
    99+
    2023-10-26
    android java android studio
  • Android studio自定义对话框效果
    本文实例为大家分享了Android studio自定义对话框效果的具体代码,供大家参考,具体内容如下 实现步骤: 第一步:自定义.xml布局文件 <?xml ver...
    99+
    2024-04-02
  • android自定义带箭头对话框
    本文实例为大家分享了android自定义带箭头对话框的具体代码,供大家参考,具体内容如下 import android.content.Context; import andr...
    99+
    2024-04-02
  • android自定义对话框实例代码
    1.实现效果    2.定义dialog.xml (res/layout/dialog.xml) <?xml version="1.0" encoding="utf...
    99+
    2024-04-02
  • Android如何自定义升级对话框示例详解
    前言本文主要给大家介绍了关于Android自定义升级对话框的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧。实现的效果如下所示其实这也只是一个DialogFragment 而已,重点只是在于界面的设计想要使用做出这...
    99+
    2023-05-30
    android 自定义 升级对话框
  • Android自定义对话框的简单实现
    本文实例为大家分享了Android自定义对话框的具体实现代码,供大家参考,具体内容如下 1、定义对话框的布局 <xml version="1.0" encoding="utf-...
    99+
    2024-04-02
  • Android自定义样式圆角dialog对话框
    本文实例为大家分享了Android创建自定义样式圆角dialog对话框的具体代码,供大家参考,具体内容如下 效果如上,圆角对话框,标题和正文都可以自己设定 做法: 1.在res文件...
    99+
    2024-04-02
  • Android Studio使用自定义对话框效果
    Android Studio基础使用自定义对话框,供大家参考,具体内容如下 兼容低版本的APP运行 第一步:新建新的空白activity,布局XML设置如下 该APP的启动界面ac...
    99+
    2024-04-02
  • Android自定义对话框Dialog的简单实现
    本文着重研究了自定义对话框,通过一下步骤即可清晰的理解原理,通过更改界面设置和style类型,可以应用在各种各样适合自己的App中。首先来看一下效果图:首先是activity的界面点击了上述图片的按钮后,弹出对话框:点击对话框的确定按钮:点...
    99+
    2023-05-30
    android 对话框 dialog
  • Android中怎么自定义AlertDialog对话框样式
    这篇文章给大家介绍Android中怎么自定义AlertDialog对话框样式,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。根据自己实际的需求,为AlertDialog创建一个布局,在此我需要定义一个如图所示的WIFI密...
    99+
    2023-05-30
    android alertdialog
  • Android Studio怎么使用自定义对话框效果
    这篇文章主要介绍了Android Studio怎么使用自定义对话框效果的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Android Studio怎么使用自定义对话框效果文章都会有所收获,下面...
    99+
    2023-06-30
  • Android怎么自定义样式圆角dialog对话框
    这篇文章主要介绍“Android怎么自定义样式圆角dialog对话框”,在日常操作中,相信很多人在Android怎么自定义样式圆角dialog对话框问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Android...
    99+
    2023-06-25
  • C/C++ Qt如何自定义Dialog对话框组件
    这篇文章主要介绍“C/C++ Qt如何自定义Dialog对话框组件”,在日常操作中,相信很多人在C/C++ Qt如何自定义Dialog对话框组件问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答...
    99+
    2023-06-21
  • Android中怎么自定义对话框位置及大小
    Android中怎么自定义对话框位置及大小,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。代码:package angel.devil;import an...
    99+
    2023-05-30
    android
  • Vue自定义模态对话框弹窗
    本文实例为大家分享了Vue自定义模态对话框弹窗的具体代码,供大家参考,具体内容如下 模态对话框弹窗效果: 父组件(应用页面)主要代码: <template>     &...
    99+
    2024-04-02
  • 怎么在Android中自定义一个扁平化对话框
    这篇文章给大家介绍怎么在Android中自定义一个扁平化对话框,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。Shamoo想到在Android平台上弄一个扁平化的对话框。参考过一篇帖子,然后改了一下。这个Demo比较简单...
    99+
    2023-05-31
    android
  • 微信小程序如何实现自定义对话框
    这篇文章将为大家详细讲解有关微信小程序如何实现自定义对话框,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。微信小程序 自定义对话框实例详解效果图:index.wxml:&l...
    99+
    2024-04-02
  • 微信小程序如何自定义模态对话框
    这篇文章给大家分享的是有关微信小程序如何自定义模态对话框的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。由于官方API提供的显示模态弹窗,只能简单地显示文字内容,不能对对话框内容进...
    99+
    2024-04-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作