项目结构:

MainActivity:

package com.example.demo_three;import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);findViewById(R.id.button).setOnClickListener(new View.OnClickListener(){@Overridepublic void onClick(View v) {Toast.makeText(MainActivity.this, "click", Toast.LENGTH_SHORT).show();LayoutInflater inflater=MainActivity.this.getLayoutInflater();View dialog=inflater.inflate(R.layout.dialog_view,null);AlertDialog.Builder builder=new AlertDialog.Builder(MainActivity.this);builder.setIcon(R.drawable.u).setTitle("用户登录").setView(dialog).setPositiveButton("登录", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {Toast.makeText(MainActivity.this, "登录成功", Toast.LENGTH_SHORT).show();}});builder.create().show();}});}
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity"><Buttonandroid:id="@+id/button"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

dialog_view.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:id="@+id/textView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="用户名:" /><EditTextandroid:id="@+id/editText"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:ems="10"android:inputType="textPersonName"android:text="" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:id="@+id/textView2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="密    码:" /><EditTextandroid:id="@+id/editText2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:ems="10"android:inputType="textPersonName"android:text="" /></LinearLayout></LinearLayout>
</LinearLayout>

演示:

Android对话框动态加载布局相关推荐

  1. Android:动态加载布局

    使用LayoutInflater类的inflate函数,将第一个参数的布局加载到第二个参数的布局上. 第一个参数是个int对应一个布局文件,第二个参数是个View对象实例. getMenuInflat ...

  2. Android动态加载布局

    最近一直比较忙,博客没及时写.最近项目中用到了动态加载布局,今天闲下来记录一下自己的学习经历吧. ListView我们一直都在用,只不过当Adapter中的内容比较多的时候我们有时候没办法去设置一些组 ...

  3. Android apk动态加载机制的研究(二):资源加载和activity生命周期管理

    转载请注明出处:http://blog.csdn.net/singwhatiwanna/article/details/23387079 (来自singwhatiwanna的csdn博客) 前言 为了 ...

  4. java layoutinflater_使用LayoutInflater动态加载布局和操作控件

    我们知道在Android中通过布局文件来描述软件的界面,而通常在Activity中都是使用setContentView()来将布局显示出来.但是如果我们在非Activity的情况下,而且需要对布局中的 ...

  5. Android类动态加载技术

    Android类动态加载技术 Android应用开发在一般情况下,常规的开发方式和代码架构就能满足我们的普通需求.但是有些特殊问题,常常引发我们进一步的沉思.我们从沉思中产生顿悟,从而产生新的技术形式 ...

  6. Android基础——动态加载so库

    Android中动态加载so 原因:如果把so文件直接放在libs目录下,在android程序启动的时候会默认加载libs目录下的所有so库,但这些so库可能会在某些地方存在冲突,使用动态加载so库, ...

  7. Android使用addView动态加载布局文件

    第一步,要获取要将动态加载内容置入的容器 relativeLayout RelativeLayout relativeLayout = (RelativeLayout) findViewById(R. ...

  8. Android app动态加载

    在 Java 里面,我们可以把一些类放到 .jar 文件里面,然后用 ClassLoader 动态加载.例如: [java] view plaincopyprint? URLClassLoader u ...

  9. Android动态替换dex,Android DexClassLoader动态加载与插件化开发

    参考链接: 一. 基本概念和注意点 1.1 首先需要了解一点:在Android中可以动态加载,但无法像Java中那样方便动态加载jar 原因:Android的虚拟机(Dalvik VM)是不认识Jav ...

最新文章

  1. Science子刊: 长期杀虫剂诱导选择下的宿主基因组与微生物组的共适应
  2. EOS 智能合约源代码解读 (10)token合约“几种关键操作”
  3. Python enumerate索引迭代
  4. “云网管” -云上构建网络自动化体系
  5. 由「Metaspace容量不足触发CMS GC」从而引发的思考
  6. 【长文综述】基于图神经网络的知识图谱研究进展
  7. php 获取刚插入的一条,php获得刚插入数据的id 的几种方法
  8. 寻找固定的和----2013年2月26日
  9. 硬件课程设计:步进电机控制系统
  10. python求t分布值_简单数据分布分析与python实现,及
  11. 80386汇编_全局描述表GDT介绍
  12. 电脑计算机 回收站隐藏文件,电脑中怎样隐藏回收站?电脑中隐藏回收站方法【图文】...
  13. 发布Flask项目到服务器
  14. Cookie跨域setDomain
  15. 数学建模美赛写作指导20篇(七)-美赛优缺点英文表达
  16. Allegro修改shape网络节点
  17. 使用uniapp框架搭建浙里办微应用(单点登录、埋点、适老化、RPC网关)
  18. JavaGUI显示表格(连接数据库)基础
  19. TEE OS中断篇(五):FIQ的事件处理
  20. STAPLE目标跟踪算法 基于C++ /Opencv实现步骤以及代码详解

热门文章

  1. RPC 的超时设置,一不小心就是线上事故!
  2. 罗永浩直播首秀开卖小米 10;微信能转账 QQ;Ruby 2.7.1 发布 | 极客头条
  3. 支付宝核心工程师谈如何成为一名优秀的程序员?
  4. 苹果发布会不够酷?库克又送来了 iOS 12.2!
  5. IT 从业者要如何在国企「活」下去?
  6. 黑客利用智能灯泡窃取用户数据!
  7. 为什么我会弃Java,选择了Kotlin——专访《Java编程思想》作者 Bruce Eckel
  8. 4 年创 40 亿美元业绩神话,比特币挖矿究竟有多赚钱?
  9. 一文带你了解人工智能最新进展:AI从业者如何选择技术路线?
  10. ThreadLocal到底是什么,尚硅谷docker高级