当前位置: 首页 > ops >正文

Android Activity 的对话框(Dialog)样式

Android Activity 的对话框(Dialog)样式

Activity 可以设置成 dialog 样式出现,主要通过 manifest 配置中 <activity> 标签的 android:theme 属性值实现,亦或通过代码设置方式 setTheme(int) 修改 Activity 出现的样式。
这篇文章中测试设备是一台手机。

程序基本构建配置:

android {compileSdk = 35defaultConfig {applicationId = "com.sanren1024.dialog"minSdk = 30this.targetSdk = 35versionCode = 1versionName = "1.0.0.0"testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"}
// ...
}

下面列举若干个 theme 对应的页面出现的样式,通过代码方式设置 theme.


android.R.style.Theme_Dialog

Theme_Dialog

这个普通的 Dialog 样式,ActionBar 背景色是黑色。


Material

android.R.style.Theme_Material_Dialog

Theme_Material_Dialog

这个样式中,整个背景是黑色,带有 ActionBart 的一个 Dialog 样式。与上面的区别是在 ActionBar 的颜色不同,布局有所不同。


android.R.style.Theme_Material_Dialog_Alert

Theme_Material_Dialog_Alert

这个 Dialog 样式与 android.R.style.Theme_Material_Dialog 一致。


android.R.style.Theme_Material_DialogWhenLarge

Theme_Material_DialogWhenLarge

这个样式的 Activity,基本与不设置 Dialog 样式的 Activity 一致,不类似于上面几个样式,会修改底部 NavigationBar 的背景色,这一个样式没有修改它的颜色。


android.R.style.Theme_Material_DialogWhenLarge_NoActionBar

Theme_Material_DialogWhenLarge_NoActionBar

这个样式在 android.R.style.Theme_Material_DialogWhenLarge 基础上移除了 ActionBar。


android.R.style.Theme_Material_Dialog_MinWidth

Theme_Material_Dialog_MinWidth


android.R.style.Theme_Material_Dialog_NoActionBar

Theme_Material_Dialog_NoActionBar


android.R.style.Theme_Material_Dialog_NoActionBar_MinWidth

Theme_Material_Dialog_NoActionBar_MinWidth


android.R.style.Theme_Material_Dialog_Presentation

Theme_Material_Dialog_Presentation

这个样式比较不同,将 StatusBar 都遮蔽了。


Material_Light

android.R.style.Theme_Material_Light_Dialog

Theme_Material_Light_Dialog


android.R.style.Theme_Material_Light_Dialog_Alert

Theme_Material_Light_Dialog_Alert


android.R.style.Theme_Material_Light_Dialog_Presentation

Theme_Material_Light_Dialog_Presentation


android.R.style.Theme_Material_Light_DialogWhenLarge

Theme_Material_Light_DialogWhenLarge


android.R.style.Theme_Material_Light_Dialog_MinWidth

Theme_Material_Light_Dialog_MinWidth


android.R.style.Theme_Material_Light_DialogWhenLarge_DarkActionBar

Theme_Material_Light_DialogWhenLarge_DarkActionBar


android.R.style.Theme_Material_Light_DialogWhenLarge_NoActionBar

Theme_Material_Light_DialogWhenLarge_NoActionBar


android.R.style.Theme_Material_Light_Dialog_NoActionBar

Theme_Material_Light_Dialog_NoActionBar


android.R.style.Theme_Material_Light_Dialog_NoActionBar_MinWidth

Theme_Material_Light_Dialog_NoActionBar_MinWidth


DeviceDefault

android.R.style.Theme_DeviceDefault_Dialog

Theme_DeviceDefault_Dialog


android.R.style.Theme_DeviceDefault_DialogWhenLarge

Theme_DeviceDefault_DialogWhenLarge


android.R.style.Theme_DeviceDefault_Dialog_MinWidth

Theme_DeviceDefault_Dialog_MinWidth


android.R.style.Theme_DeviceDefault_DialogWhenLarge_NoActionBar

Theme_DeviceDefault_DialogWhenLarge_NoActionBar


android.R.style.Theme_DeviceDefault_Dialog_Alert

Theme_DeviceDefault_Dialog_Alert


android.R.style.Theme_DeviceDefault_Dialog_NoActionBar

Theme_DeviceDefault_Dialog_NoActionBar


android.R.style.Theme_DeviceDefault_Dialog_NoActionBar_MinWidth

Theme_DeviceDefault_Dialog_NoActionBar_MinWidth


DeviceDefault_Light

android.R.style.Theme_DeviceDefault_Light_Dialog

Theme_DeviceDefault_Light_Dialog


android.R.style.Theme_DeviceDefault_Light_DialogWhenLarge

Theme_DeviceDefault_Light_DialogWhenLarge


android.R.style.Theme_DeviceDefault_Light_DialogWhenLarge_NoActionBar

Theme_DeviceDefault_Light_DialogWhenLarge_NoActionBar


android.R.style.Theme_DeviceDefault_Light_Dialog_Alert

Theme_DeviceDefault_Light_Dialog_Alert


android.R.style.Theme_DeviceDefault_Light_Dialog_NoActionBar

Theme_DeviceDefault_Light_Dialog_NoActionBar


android.R.style.Theme_DeviceDefault_Light_Dialog_NoActionBar_MinWidth

Theme_DeviceDefault_Light_Dialog_NoActionBar_MinWidth


android.R.style.Theme_DeviceDefault_Light_Dialog_MinWidth

Theme_DeviceDefault_Light_Dialog_MinWidth


Overlay

android.R.style.ThemeOverlay_Material_Dialog

ThemeOverlay_Material_Dialog


android.R.style.ThemeOverlay_Material_Dialog_Alert

ThemeOverlay_Material_Dialog_Alert

总结

Dialog 样式主要的风格是 Material 样式和 DeviceDefault 样式。
两者的主要区别如下表。

MaterialDeviceDefault
遵循 Google 的 Material Design 设计预言,强调阴影、圆角、动态色彩和交互动画(如水波纹效果)。继承设备制造商(如三星 One UI、小米 MIUI)的自定义主题,视觉风格由厂商定义。
仅支持 Android 5.0+(API 21)从 Android 4.0(API 14)开始
自定义灵活性高自定义灵活性低
视觉效果一致因厂商而异
http://www.xdnf.cn/news/17636.html

相关文章:

  • LaTeX(排版系统)Texlive(环境)Vscode(编辑器)环境配置与安装
  • PostgreSQL——索引
  • SpringBoot工程妙用:不启动容器也能享受Fat Jar的便利
  • Redis:是什么、能做什么?
  • 第十三节:后期处理:效果增强
  • MySQL优化常用的几个方法
  • 使用 Python Selenium 和 Requests 实现歌曲网站批量下载实战
  • 100、【OS】【Nuttx】【构建】cmake 配置保存
  • 文心4.5专家负载均衡机制深度解析
  • 【Virtual Globe 渲染技术笔记】4 椭球面上的曲线
  • 线上Linux服务器被植入各种病毒的详细分析、处理、加固流程
  • 机器学习之TF-IDF文本关键词提取
  • EP1S20F484C6 Altera Stratix FPGA
  • imx6ull-驱动开发篇19——linux信号量实验
  • 鸿蒙开发资源导航与学习建议
  • 如何解决Unexpected token ‘<’, “<!doctype “… is not valid JSON 报错问题
  • 微服务ETCD服务注册和发现
  • LeetCode 2787.将一个数字表示成幂的和的方案数:经典01背包
  • Airtable 入门指南:从创建项目到基础数据分析与可视化
  • 渗透测试现已成为 CISO 战略的核心
  • 开疆智能Ethernet转ModbusTCP网关连接PAC3200电能表配置案例
  • 企业高性能web服务器(4)
  • 【运维进阶】Ansible 自动化
  • AI重构Java开发:飞算JavaAI如何实现效率与质量的双重突破?
  • 计算机网络摘星题库800题笔记 第6章 应用层
  • [Robotics_py] 机器人运动模型 | `update`函数 | 微积分矩阵
  • Visual Studio中VC++目录、C/C++和链接器配置的区别与最佳实践
  • 北京JAVA基础面试30天打卡08
  • 【问题解决】从Anaconda环境迁移到miniforge并在IDEA中完成环境配置
  • K8S学习---- Kubernetes 架构:从控制平面到工作节点的协作逻辑