iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >Android编程自定义Dialog的方法分析
  • 334
分享到

Android编程自定义Dialog的方法分析

方法自定义dialogdialogAndroid 2022-06-06 11:06:50 334人浏览 安东尼
摘要

本文实例讲述了Android编程自定义Dialog的方法。分享给大家供大家参考,具体如下: 功能: android 提供给我们的只有2种Dialog 即 AlertDialog

本文实例讲述了Android编程自定义Dialog的方法。分享给大家供大家参考,具体如下:

功能:

android 提供给我们的只有2种Dialog 即 AlertDialog & ProgressDialog 但是 Dialog 有其自身的特点:1. 不是 Activity 2. 开销比 Activity 小得多

鉴于以上的优点 我们就有定制自己Dialog 的需求

原理:

1. android 系统提供了一个class: Dialog. 而且你可以把自己的工作放在"

protected void onCreate(Bundle savedInstanceState)
" 在里面先调用系统的"
super.onCreate(savedInstanceState)
" 其就会保证调用这个method.

2. 至于 Dialog 界面的定制 可以写一个xml 文件 然后 在 "

void onCreate(Bundle)
" 通过 "
setContentView()
" 来使之生效

3. Dialog 使用问题: 1. 弹出:

show()
2. 取消:
dismiss()

代码:

1. 创建一个 Dialog:


public class CustomDialog extends Dialog {
  public CustomDialog(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
  }
  protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.custom_dialog);
    setTitle("Custom Dialog");
    TextView text = (TextView)findViewById(R.id.text);
    text.setText("Hello, this is a custom dialog!");
    ImageView image = (ImageView)findViewById(R.id.image);
    image.setImageResource(R.drawable.sepurple);
    Button buttonYes = (Button) findViewById(R.id.button_yes);
    buttonYes.setHeight(5);
    buttonYes.setOnClickListener(new Button.OnClickListener(){
      public void onClick(View v) {
        // TODO Auto-generated method stub
        dismiss();
      }
    });
    Button buttonNo = (Button) findViewById(R.id.button_no);
    buttonNo.setSingleLine(true);
    buttonNo.setOnClickListener(new Button.OnClickListener(){
      public void onClick(View v) {
        // TODO Auto-generated method stub
        dismiss();
      }
    });
  }
  //called when this dialog is dismissed
  protected void onStop() {
    Log.d("TAG","+++++++++++++++++++++++++++");
  }
}

2. Dialog 的使用:


public class CustomDialogUsage extends Activity {
  CustomDialog cd;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    cd = new CustomDialog(this);
    Button buttonYes = (Button) findViewById(R.id.main_button);
    buttonYes.setOnClickListener(new OnClickListener(){
      public void onClick(View v) {
        // TODO Auto-generated method stub
        cd.show();
      }
    });
  }
}

3. Dialog 的界面定制:


<LinearLayout xmlns:android="Http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="10dp">
  <ImageView android:id="@+id/image" android:layout_width="wrap_content"
  android:layout_height="fill_parent" android:layout_marginRight="10dp"
  />
  <LinearLayout android:orientation="vertical"
  android:layout_width="fill_parent" android:layout_height="wrap_content"
  android:padding="5px">
    <TextView android:id="@+id/text" android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:textColor="#FFF" />
    <LinearLayout android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="5px">
      <Button android:id="@+id/button_yes"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text=" Yes " android:gravity="center"
      />
      <Button android:id="@+id/button_no"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text=" No " android:gravity="center"
      />
    </LinearLayout>
  </LinearLayout>
</LinearLayout>

更多关于Android相关内容感兴趣的读者可查看本站专题:《Android开发入门与进阶教程》、《Android调试技巧与常见问题解决方法汇总》、《Android多媒体操作技巧汇总(音频,视频,录音等)》、《Android基本组件用法总结》、《Android视图View技巧总结》、《Android布局layout技巧总结》及《Android控件用法总结》

希望本文所述对大家Android程序设计有所帮助。

您可能感兴趣的文章:Android自定义dialog可选择展示年月日时间选择栏Android中用Builder模式自定义Dialog的方法Android自定义Dialog实现文字动态加载效果Android 自定义Dialog 实例Android UI设计系列之自定义Dialog实现各种风格的对话框效果(7)Android中制作自定义dialog对话框的实例分享Android自定义dialog简单实现方法Android编程经典代码集锦(复制,粘贴,浏览器调用,Toast显示,自定义Dialog等)Android编程中自定义dialog用法实例Android 去掉自定义dialog的白色边框的简单方法Android 自定义dialog的实现代码


--结束END--

本文标题: Android编程自定义Dialog的方法分析

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

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

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

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

下载Word文档
猜你喜欢
  • android自定义dialog的方法是什么
    Android中自定义Dialog的方法有以下几种:1. 创建一个继承自Dialog类的自定义对话框:- 创建一个新的类,继承自Di...
    99+
    2023-09-21
    android
  • Android自定义Dialog的2种常见方法
    目录前言方式一:继承DialogFragment,也是官方推荐的方式事例方式二:直接继承Dialog类或者AppCompatDialog类更新前言 大多数中,使用系统内置的dialo...
    99+
    2024-04-02
  • Android编程中自定义组件的示例分析
    这篇文章主要介绍了Android编程中自定义组件的示例分析,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。Android是什么Android是一种基于Linux内核的自由及开放...
    99+
    2023-05-31
    android
  • Android如何实现自定义Dialog的大小
    小编给大家分享一下Android如何实现自定义Dialog的大小,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!具体如下:Android应用开发中,无论是出于功能还...
    99+
    2023-05-30
    android dialog
  • Android编程实现自定义ImageView圆图功能的方法
    本文实例讲述了Android编程实现自定义ImageView圆图功能的方法。分享给大家供大家参考,具体如下:首先很感谢开源项目Universal Image Loader图片加载框架。之前也看过一段时间框架源码,但是却没有时间进行知识点的总...
    99+
    2023-05-30
    android 自定义 imageview
  • Android中自定义的dialog中的EditText无法弹出输入法解决方案
    1.解决无法弹出输入法:  在show()方法调用之前,用dialog.setView(new EditText(context))添加一个空的EditText,由于是自定义的AlertDialog,有我们指定的布局,所以设置这个不会影响我...
    99+
    2023-05-31
    dialog edittext 输入法
  • Android自定义对话框Dialog的简单实现
    本文着重研究了自定义对话框,通过一下步骤即可清晰的理解原理,通过更改界面设置和style类型,可以应用在各种各样适合自己的App中。首先来看一下效果图:首先是activity的界面点击了上述图片的按钮后,弹出对话框:点击对话框的确定按钮:点...
    99+
    2023-05-30
    android 对话框 dialog
  • Android通过自定义Activity实现悬浮的Dialog详解
    前言其实实现悬浮的自定义窗体有很多方法,自定义Dialog,自定义layout 均可以实现。自定义activity也是可以的,今天我就介绍一下activity的实现方法。下面来看看详细的介绍:效果图如图可以看出,当前的窗体,第一眼其实和di...
    99+
    2023-05-31
    android 悬浮dialog 自定义activity
  • Android自定义弹出框的方法
    在开发Android项目的过程中,弹出框真的是我们的常见的一种互动式窗体,但是Android系统自带的弹出框往往都不能满足我们的需要,大多数的时候需要我们自定义一种更漂亮的窗体来来展...
    99+
    2024-04-02
  • Android自定义加载圈的方法
    本文实例为大家分享了Android自定义加载圈的具体代码,供大家参考,具体内容如下 <RelativeLayout xmlns:android="http://schemas...
    99+
    2024-04-02
  • Android编程实现activity dialog透明背景的方法
    本文实例讲述了Android编程实现activity dialog透明背景的方法。分享给大家供大家参考,具体如下:首先查一下window  activity的关系具体省略。。。。我的理解就是每个activity都有一个window...
    99+
    2023-05-31
    android activity dialog
  • Android编程实现AlertDialog自定义弹出对话框的方法示例
    本文实例讲述了Android编程实现AlertDialog自定义弹出对话框的方法。分享给大家供大家参考,具体如下:弹出对话框,显示自定义的布局文件弹出对话框提示设置密码或登录密码private void showSetPasswordDia...
    99+
    2023-05-30
    android alertdialog 对话框
  • android自定义seekbar的方法是什么
    要自定义SeekBar,你可以使用xml布局文件和自定义的Style来实现。以下是一个简单的示例: 创建一个名为custom_se...
    99+
    2024-04-02
  • android自定义控件的方法是什么
    Android自定义控件的方法有以下几种:1. 继承系统控件:可以通过继承系统控件来进行扩展和定制。通过重写控件的绘制方法,修改控件...
    99+
    2023-08-16
    android
  • 解析iReport自定义行数分页的操作方法
    iReport 是为JasperReports Library和JasperReports Server设计的报表可视化设计器。iReport是一个能够创建复杂报表的开源项目。它10...
    99+
    2024-04-02
  • Android自定义view绘制表格的方法
    本文实例为大家分享了Android自定义view绘制表格的具体代码,供大家参考,具体内容如下 先上效果图 平时很少有这样的表格需求,不过第一想法就是自定义view绘制表格,事实上我...
    99+
    2024-04-02
  • android中自定义view的方法有哪些
    在Android中,可以通过以下几种方式来自定义View:1. 继承View类:创建一个继承自View类的子类,并实现相应的绘制方法...
    99+
    2023-10-18
    android
  • php怎么编写自定义方法
    PHP是一种流行的服务器端编程语言,它可以创建动态网页和Web应用程序。尽管PHP拥有许多内置的函数和方法,但有时候,您可能需要自定义方法来完成某些任务。在本文中,我们将讨论如何编写自定义的PHP方法。创建自定义函数创建自定义函数需要使用 ...
    99+
    2023-05-14
    php
  • php如何编写自定义方法
    这篇文章主要介绍了php如何编写自定义方法的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇php如何编写自定义方法文章都会有所收获,下面我们一起来看看吧。创建自定义函数创建自定义函数需要使用 PHP 中的 fun...
    99+
    2023-07-05
  • Android自定义仿ios加载弹窗的示例分析
    小编给大家分享一下Android自定义仿ios加载弹窗的示例分析,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!具体内容如下效果如下:IosLoadDialog类(可直接复制):public class ...
    99+
    2023-06-15
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作