zoukankan      html  css  js  c++  java
  • Android开发学习笔记-自定义对话框

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

    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、通过以上设置就可自定义对话框

  • 相关阅读:
    常用 SQL 语句使用的总结
    LC 583. Delete Operation for Two Strings
    LC 873. Length of Longest Fibonacci Subsequence
    LC 869. Reordered Power of 2
    LC 900. RLE Iterator
    LC 974. Subarray Sums Divisible by K
    LC 973. K Closest Points to Origin
    LC 975. Odd Even Jump
    LC 901. Online Stock Span
    LC 722. Remove Comments
  • 原文地址:https://www.cnblogs.com/xuhongfei/p/4014747.html
Copyright © 2011-2022 走看看