码迷,mamicode.com
首页 > 移动开发 > 详细

Android开发学习笔记-自定义对话框

时间:2014-10-13 00:18:38      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   http   color   io   使用   ar   sp   

    系统默认的对话框只能显示简单的标题内容以及按钮,而如果想要多现实其他内容则就需要自定义对话框,下面是自定义对话框的方法。

1、先定义对话框的模版

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="300dp"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <TextView 
        android:id="@+id/tv_title"
        android:layout_width="300dp"
        android:layout_height="30dp"
      
     android:textSize="22sp"
     android:text="设置中心"
        android:gravity="center"/>
<EditText
    android:id="@+id/ed_password"
    android:layout_width="300dp"
    android:layout_height="50dp"
  
     android:textSize="22sp"
    android:hint="输入密码"
    />
<EditText 
    android:id="@+id/ed_re_password"
    android:layout_width="300dp"
    android:layout_height="50dp"
   
      android:textSize="22sp"
       android:hint="重新输入密码"
    />
<LinearLayout 
    android:layout_height="wrap_content"
    android:layout_width="300dp"
   android:orientation="horizontal"
   android:gravity="center_horizontal"
    >
    
    <Button 
        android:id="@+id/btn_ok"
       android:text="确定"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
     <Button 
        android:id="@+id/btn_cancel"
        android:text="取消"
       
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
</LinearLayout>
</LinearLayout>

2、之后将使用对话框模版将对话框重新渲染。

AlertDialog.Builder dialog = new Builder(this);
        
        View view = View.inflate(MainActivity.this, R.layout.set_password_dialog, null);
        dialog.setView(view);
        dialog.show();

3、通过以上设置就可自定义对话框

Android开发学习笔记-自定义对话框

标签:android   style   blog   http   color   io   使用   ar   sp   

原文地址:http://www.cnblogs.com/xuhongfei/p/4014747.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!