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

  • 相关阅读:
    Supervisor安装与使用
    windows常用快捷键和指令
    搜索引擎使用技巧
    golang核心Goroutine和channel
    4、小程序原生底部菜单
    三、小程序值使用vant开发
    axios请求2
    3、小程序消息推送
    居中
    一、底部菜单
  • 原文地址:https://www.cnblogs.com/xuhongfei/p/4014747.html
Copyright © 2011-2022 走看看