Android编程中自定义dialog用法实例
作者:chenguang79 发布时间:2023-05-10 07:21:37
标签:Android,dialog
本文实例讲述了Android编程中自定义dialog用法。分享给大家供大家参考,具体如下:
dialog是android中提供的一组弹出提示框,非常好用,可是它的样式是一个定式,有时候我们需求定义一些自己的样式
1、定义一个样式文件,此文件继承自Theme.Dialog,在style.xml文件中建立一个自己的样式
<style name="addNoteType_error_Dialog" parent="@android:Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@color/color_shenhui</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
2、新建一个layout,做为弹出框的显示
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#DFDFDF">
<TextView
android:layout_width="fill_parent"
android:layout_height="50dp"
android:gravity="center_vertical"
android:layout_marginLeft="5dp"
android:text="@string/txt_addnoteType_error_title"
android:textColor="#00CCFF"
android:textSize="18sp"
/>
<View
android:layout_width="fill_parent"
android:layout_height="1px"
android:background="#00CCFF"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="50dp"
android:gravity="left|center"
android:layout_marginTop="5dp"
android:text="@string/txt_addnoteType_error_content_null"
/>
<View
android:layout_width="fill_parent"
android:layout_height="1px"
android:background="#BBB9BA"
android:layout_marginTop="5dp"
/>
<Button
android:id="@+id/btn_add_note_addnotetype_Error_ok"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="@string/txt_ok"
android:background="@null"
/>
</LinearLayout>
3、调用此dialog
//此处直接new一个Dialog对象出来,在实例化的时候传入主题
dialog = new Dialog(Sel_NoteTypeActivity.this, R.style.addNoteType_error_Dialog);
//设置它的ContentView
dialog.setContentView(R.layout.dialog_addnotetype_error);
Button btn_add_note_addnotetype_Error_ok = (Button)dialog.findViewById(R.id.btn_add_note_addnotetype_Error_ok);
btn_add_note_addnotetype_Error_ok.setOnClickListener(new addnoteTypeErroClickListener());
dialog.show();
按钮点击事件:
class addnoteTypeErroClickListener implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
dialog.cancel();
}
}
有时候,我们会想设置dialog的宽或高,这个还是比较简单的,直接在dialog.show()下面添加如下代码:
WindowManager.LayoutParams Layoutparams = dialog.getWindow().getAttributes();
Layoutparams.width = (int)(mScreenWidth *9 / 10); //设置宽度
dialog.getWindow().setAttributes(Layoutparams);
希望本文所述对大家Android程序设计有所帮助。


猜你喜欢
- 本文实例讲述了Android编程之利用服务实现 * 听的方法。分享给大家供大家参考,具体如下:1. 启动模拟器,部署应用2. 利用模拟器控制
- 本文实例讲述了C#使用iTextSharp封装的PDF文件操作类。分享给大家供大家参考。具体分析如下:这个C#代码主要讲iTextSharp
- 1、python的每一个语句的后面可以添加分号也可以不添加分号;在一行有多条语句的时候,必须使用分号加以区分2、查看Python版本号,在D
- 现在许多系统的注册、登录或者发布信息模块都添加的随机码功能,就是为了避免自动注册程序或者自动发布程序的使用。验证码实际上就是随机选择一些字符
- 问题描述需要定时通过websocket接口来推送mysql里面最新的数据,自定义了定时器@Component@Slf4jpublic cla
- 在C语言中一般用typedef来为回调函数定义别名(参数名)。 别名通过宏定义typedef来实现,不是简单的宏替换。可以用作同
- 本文实例为大家分享了java实现抽奖功能的具体代码,供大家参考,具体内容如下抽一个:输入抽奖人数,生成随机数字进行抽奖。比如:楼主抽幸运儿送
- 详解xamarin Android 实现ListView万能适配器早些时候接触xamarin Android 的列表,写了很多ListVie
- 通过路径从磁盘直接读取图片这段时间在做Springboot和Vue的例子,读取图片给出路径直接可以读,太方便了,一直么有搞懂为什么。后面看到
- 先上一张效果图using UnityEngine;using System.Collections;public class TestRot
- 有时候在单机部署,或者项目没有在IDea 开发工具中运行(idea可以自动打开tomcat项目),需要项目启动后自动打开浏览器访问项目,配置
- 一、程序运行环境编译环境:IntelliJ IDEA所需测试文件:PDF、.pfx数字证书及密钥、PDF Jar包(Free Spire.P
- 本文实例讲述了Java Swing实现窗体添加背景图片的2种方法。分享给大家供大家参考,具体如下:在美化程序时,常常需要在窗体上添加背景图片
- 注:完整项目下载在处理了核心任务之后,我们会发现有些请求并不是都是静态的,那么我们就需要进行实现处理动态请求的要求,如下面代码是我们请求的解
- 在上一篇文章中我介绍了使用Intent显式来实现页面向下跳转,接下来这篇文章主要介绍的是使用Intent隐式来实现向上跳转,什么意思呢,就是
- 具体详情如下所示:int -> Stringint i=12345;String s="";第一种方法:s=i+&
- SlidingDrawer隐藏屏外的内容,并允许用户通过handle以显示隐藏内容。它可以垂直或水平滑动,它有俩个View组成,其一是可以拖
- spring boot 使用POI读取Excel文件Excel文件目录Excel模板文件存了resourse目录下,如下图:<depe
- 单例模式是最常用到的设计模式之一,熟悉设计模式的朋友对单例模式都不会陌生。一般介绍单例模式的书籍都会提到 饿汉式 和 懒汉式 这两种实现方式
- 系列文章已完成,目录如下:commons-logging与jdk-logging、log4j1、log4j2、logback的集成原理slf