最重要的是这两行代码
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);//设置Dialog没有标题,需在setContentView之前设置
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);//设置Dialog背景透明效果
MainActivity
public class MainActivity extends ListActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] array = { "不指定Dialog的主题,指定Activity使用系统定义的主题", //
"指定Dialog使用系统定义的主题", //
"设置Dialog无标题、背景透明效果", //
"设置AlertDialog背景透明效果", };
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new ArrayList<String>(Arrays.asList(array))));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
switch (position) {
case 0:
startActivity(new Intent(this, Activity1.class));
break;
case 1:
startActivity(new Intent(this, Activity2.class));
break;
case 2:
Dialog dialog = new Dialog(this);//直接设置对话框主题
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);//设置Dialog没有标题。需在setContentView之前设置,在之后设置会报错
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);//设置Dialog背景透明效果
dialog.setContentView(R.layout.layout_dialog);
dialog.show();
break;
case 3:
AlertDialog alertDialog = new AlertDialog.Builder(this).setView(R.layout.layout_dialog).create();
alertDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);//设置Dialog背景透明效果
alertDialog.show();
break;
}
}
}
Activity1
public class Activity1 extends ListActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] array = { "【Theme_Light】AlertDialog 宽高均会压缩到最小,背景上下部分有多余的黑色",//【不能用】
"Dialog 对于内容而言,宽高均为设置的值,自带一个标题栏,宽度不会拉伸及填充", //【去掉标题后问题基本不存在了】
//
"【Theme_Holo_Light】AlertDialog 高会压缩到最小,宽为固定值,背景无多余的黑色", //【能用,但background圆角大于1dp的话,背景会有点小瑕疵】
"Dialog 对于内容而言,宽高均为设置的值,自带一个标题栏,宽度会被拉伸为一个固定值", //【去掉标题后问题基本不存在了】
//
"【 Theme_DeviceDefault_Light 】\n 设备默认根主题,与手机系统有关", "", //
//
"【Theme_Material_Light】AlertDialog 高会压缩到最小,宽为固定值,背景无多余的黑色", //【能用,但background圆角大于1dp的话,背景会有点小瑕疵】
"Dialog 对于内容而言,宽高均为设置的值,自带一个标题栏,宽度会被拉伸为一个固定值", };//【去掉标题后问题基本不存在了】
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new ArrayList<String>(Arrays.asList(array))));
setTitle("指定Activity使用系统定义的主题");
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
switch (position) {
case 0://
case 1:
SystemThemeActivity.launch(this, android.R.style.Theme_Light, "Theme_Light", position % 2);
break;
case 2://
case 3:
SystemThemeActivity.launch(this, android.R.style.Theme_Holo_Light, "Theme_Holo_Light", position % 2);
break;
case 4://
case 5:
SystemThemeActivity.launch(this, android.R.style.Theme_DeviceDefault_Light, "Theme_DeviceDefault_Light", position % 2);
break;
case 6://
case 7:
SystemThemeActivity.launch(this, android.R.style.Theme_Material_Light, "Theme_Material_Light", position % 2);
break;
}
}
}
Activity2
public class Activity2 extends ListActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] array = { "【AlertDialog.THEME_HOLO_LIGHT】\nAlertDialog 和在Activity中设置此样式时一样",//【能用】,但background圆角大于1dp的话,背景会有点小瑕疵
"Dialog 效果真奇葩", //【不能用】
"【AlertDialog.THEME_DEVICE_DEFAULT_】\nAlertDialog 和在Activity中设置此样式时一样", //【能用】,但background圆角大于1dp的话,背景会有点小瑕疵
"Dialog 效果真奇葩", //【不能用】
"【Theme_Dialog】\nAlertDialog 效果真奇葩", //【不能用】
"Dialog 效果和在Activity中设置Theme_Light一样", // 对于内容而言,宽高均为设置的值,自带一个标题栏,宽度不会拉伸及填充【去掉标题后问题基本不存在了】
"【更改Theme_Dialog部分属性】AlertDialog 效果和在Activity中设置Theme_Light一样", //【不能用】宽高均会压缩到最小,背景上下部分有多余的黑色
"Dialog 非常完美,大部分自定义Dialog都是这么干的!但是高版本推荐使用DialogFragment", };//【非常完美】
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new ArrayList<String>(Arrays.asList(array))));
setTitle("指定Dialog使用系统定义的主题");
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
switch (position) {
case 0://
case 1:
SystemThemeDialogActivity.launch(this, AlertDialog.THEME_HOLO_LIGHT, "AlertDialog.THEME_HOLO_LIGHT", position % 2);
break;
case 2://
case 3:
SystemThemeDialogActivity.launch(this, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT, "AlertDialog.THEME_DEVICE_DEFAULT_LIGHT", position % 2);
break;
case 4://
case 5:
SystemThemeDialogActivity.launch(this, android.R.style.Theme_Dialog, "Theme_Dialog", position % 2);
break;
case 6://
case 7:
SystemThemeDialogActivity.launch(this, R.style.DialogTheme, "更改Theme_Dialog部分属性", position % 2);
break;
}
}
}
SystemThemeActivity
/**
* 不指定Dialog的主题,指定Activity使用系统定义的主题
* @author 白乾涛
*/
public class SystemThemeActivity extends Activity implements OnDismissListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
int themeId = getIntent().getIntExtra("themeId", 0);
String theme = getIntent().getStringExtra("theme");
int type = getIntent().getIntExtra("type", 0);
setTheme(themeId);//设定【Activity的主题】要放到调用父类方法之前
super.onCreate(savedInstanceState);
TextView textView = new TextView(this);
textView.setTextColor(0xffff0000);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
textView.setText(theme);
setContentView(textView);
//未指定【Dialog的主题】时,Dialog默认使用的是系统提供的dialogTheme主题
if (type == 0) {
textView.append(" AlertDialog");
new AlertDialog.Builder(this).setView(R.layout.layout_dialog).setOnDismissListener(this).create().show();
} else {
textView.append(" Dialog");
Dialog dialog = new Dialog(this);
//dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);//设置Dialog没有标题。需在setContentView之前设置,在之后设置会报错
dialog.setContentView(R.layout.layout_dialog);
dialog.setOnDismissListener(this);
dialog.show();
}
}
public static void launch(Context context, int themeId, String theme, int type) {
Intent intent = new Intent(context, SystemThemeActivity.class);
intent.putExtra("themeId", themeId);
intent.putExtra("theme", theme);
intent.putExtra("type", type);
context.startActivity(intent);
}
@Override
public void onDismiss(DialogInterface dialog) {
finish();
}
}
SystemThemeDialogActivity
/**
* 指定Dialog使用系统定义的主题
* @author 白乾涛
*/
public class SystemThemeDialogActivity extends Activity implements OnDismissListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int themeId = getIntent().getIntExtra("themeId", 0);
String theme = getIntent().getStringExtra("theme");
int type = getIntent().getIntExtra("type", 0);
TextView textView = new TextView(this);
textView.setTextColor(0xffff0000);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
textView.setText(theme);
setContentView(textView);
//未指定【Dialog的主题】时,Dialog默认使用的是系统提供的dialogTheme主题
if (type == 0) {
new AlertDialog.Builder(this, themeId).setView(R.layout.layout_dialog).setOnDismissListener(this).create().show();
} else {
Dialog dialog = new Dialog(this, themeId);//直接设置对话框主题
//dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);//设置Dialog没有标题。需在setContentView之前设置,在之后设置会报错
dialog.setContentView(R.layout.layout_dialog);
dialog.setOnDismissListener(this);
dialog.show();
}
}
public static void launch(Context context, int themeId, String theme, int type) {
Intent intent = new Intent(context, SystemThemeDialogActivity.class);
intent.putExtra("themeId", themeId);
intent.putExtra("theme", theme);
intent.putExtra("type", type);
context.startActivity(intent);
}
@Override
public void onDismiss(DialogInterface dialog) {
finish();
}
}
样式
<resources>
<style name="DialogTheme" parent="@android:style/Theme.Dialog">
<!-- 是否不显示title,这个是最重要的 -->
<item name="android:windowNoTitle">true</item>
<!-- 设置dialog显示区域外部的背景(透明),注意这里指的是dialog根布局的背景,因为本例中dialog的ContentView有圆角,所以圆角外部区域显示这个颜色 -->
<item name="android:windowBackground">@android:color/holo_red_light</item>
<!-- 设置dialog的背景(透明),注意这里不仅包含dialog根布局的背景,还包含本例中ImageView圆角外部的背景。此颜色值会覆盖掉windowBackground的值 -->
<item name="android:background">@android:color/transparent</item>
<!-- 设置灰度的值,当为1时,界面除了我们的dialog内容是高亮显示之外,其余区域都是黑色的,完全看不到其他内容,系统的默认值是0.5 -->
<item name="android:backgroundDimAmount">0.5</item>
<!-- 是否允许背景灰暗,即是否让显示区域以外使用上面设置的黑色半透明背景,设为false时,:backgroundDimAmount的值等价于0 -->
<item name="android:backgroundDimEnabled">true</item>
<!-- 是否有遮盖 -->
<item name="android:windowContentOverlay">@null</item>
<!-- 设置Dialog的windowFrame框(无) -->
<item name="android:windowFrame">@null</item>
<!-- 是否浮现在activity之上,必须设为true,否则自己独立占一个界面,这根本就不像是一个对话框了 -->
<item name="android:windowIsFloating">true</item>
<!-- 是否半透明,貌似没什么卵用 -->
<item name="android:windowIsTranslucent">true</item>
</style>
</resources>
背景
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item><shape>
<solid android:color="#0f0" />
<stroke android:width="1dp" android:color="#00f" />
<corners android:radius="10dp" />
</shape></item>
</selector>
内容
<?xml version="1.0" encoding="utf-8"?>
<!-- 注意:不同主题下显示效果大不相同 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="180dp"
android:layout_height="180dp"
android:background="@drawable/dialog_bg"
android:gravity="center_horizontal"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<EditText
android:layout_margin="5dp"
android:id="@+id/et_username"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
附件列表
- 【Android 应用开发】 ActionBar 样式详解 -- 样式 主题 简介 Actionbar 的 icon logo 标题 菜单样式修改
作者 : 万境绝尘 (octopus_truth@163.com) 转载请著名出处 : http://blog.csdn.net/shulianghan/article/details/3926916 ...
- 【Android 应用开发】 ActionBar 样式具体解释 -- 样式 主题 简单介绍 Actionbar 的 icon logo 标题 菜单样式改动
作者 : 万境绝尘 (octopus_truth@163.com) 转载请著名出处 : http://blog.csdn.net/shulianghan/article/details/3926916 ...
- android 修改系统的dialog样式
android 修改系统的dialog样式 一.觉得自定义配置文件麻烦?那就来修改系统自定义XML文件来实现修改系统dialog的样式吧. 如果是在XML中样式:首先来说下样式. 在 Style.x ...
- Android中关于系统Dialog无法全屏的问题(dialog样式)
自定义一个Dialog,继承了系统Dialog的样式.这时候会发现,即使布局文件中写的width和height都是match_parent,依然无法达到全屏的效果. 原因是:系统dialog的样式.默 ...
- MVC4 jquery 样式 主题 用法(案例)
MVC4已经自带了jquery,新建的项目,基本上什么都不用添加就可以运行,跑项目.(集成了那么多东西,jquery,modernizr,自带的默认权限,生成的模板,但是缺没有一个统一的文档或者什么去 ...
- Andriod中自定义Dialog样式的Activity点击空白处隐藏软件盘(Dialog不消失)
一.需求触发场景: 项目中需要出发带有EditText的Dialog显示,要求在编辑完EditText时,点击Dilog的空白处隐藏软键盘.但是Dialog不会消失.示例如下: 二.实现方法: 发布需 ...
- android中的样式主题和国际化
一.Android中的样式和主题 1.1样式 样式是作用在控件上的,它是一个包含一个或者多个view控件属性的集合.android style类似网页设计中的css设计思路,可以让设计 ...
- IntelliJ IDEA设置主题和背景图片(背景色)
设置主题以及背景图片 设置代码背景颜色
- c# 自定义含有标题的容器控件(标题背景为渐变色)
1.控件效果图 此效果图中的标题颜色.字号及字体可以在控件属性中设置.标题背景的渐变色及布局内容的背景色也可以在属性中设置. 2.实现的代码(用户控件) public partial class Uc ...
随机推荐
- bzoj 1112 treap树
思路:我们只要check一遍每个长度为k的区间就好啦,对于一个区间来说的最优值显然是中位数,我们显然要动态求 第k大,所以需要一个二叉搜索树,用treap就好啦. #include<bits/s ...
- jquery 美化弹出提示 漂亮的Dialog 对话框
三个不同的效果,分别是普通的警告,确认/取消,带一个输入框 本例用了jquery.alertify.js,请到演示页面查看 css文件也请到演示页面查看 JavaScript Code <scr ...
- OOD沉思录 --- 继承
一,继承只应被用来为特化层次结构建模 实际上也就是要满足LSP原则,水果类<-榴莲的继承是特化 二,派生类必须知道他们的基类,基类不应当知道他们的派生类 复用的前提 三,基类中的所有 ...
- js中箭头函数和普通函数this的区别
最近在学习angularJs的时候由于里面涉及到了箭头函数,箭头函数除了声明上有点区别以外,和普通函数最主要的区别还是在this的问题上. Js中函数中嵌套的函数this不会 “继承”.比如说以下代码 ...
- GeneXus项目启动
使用GeneXus产品开发项目时,在开始,有一些属性我会经常改一下.我现在使用的GeneXus版本是GeneXus U3,由于在做手机应用的开发,所以一般使用最新的版本,老外那边差不多两个月会有一个u ...
- 使用webgl(three.js)创建3D机房,3D机房微模块详细介绍(升级版二)
序: 上节课已经详细描述了普通机房的实现过程,文章地址(https://www.cnblogs.com/yeyunfei/p/10473021.html) 紧接着上节课的内容 我们这节可来详细讲解机房 ...
- Xcode_7_GM_seed.dmg下载
Xcode_7_GM_seed.dmg下载 Xcode_7_GM_seed.dmg 免费下载链接: http://pan.baidu.com/s/1pJ7oGAZ 密码: y5bx
- UIViewController的基本概念与生命周期
UIViewController是iOS顶层视图的载体及控制器,用户与程序界面的交互都是由UIViewController来控制的,UIViewController管理UIView的生命周期及资源的加 ...
- 【BZOJ 3622】3622: 已经没有什么好害怕的了(DP+容斥原理)
3622: 已经没有什么好害怕的了 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 683 Solved: 328 Description Input ...
- java 继承 String类
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha String 类 是 final修饰 , 是不能 继承的.