最重要的是这两行代码
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 ...
随机推荐
- 几道坑人的PHP面试题 试试看看你会不会也中招
这篇文章主要介绍了几道坑人的PHP面试题,试试看看你会不会也中招,这些题目都用了一些障眼法,需要你有一双火眼金睛哦,需要的朋友可以参考下 这几道题是在德问上看到的,感觉挺有意思,拿来给大家分享其中的陷 ...
- UVA 1400."Ray, Pass me the dishes!" -分治+线段树区间合并(常规操作+维护端点)并输出最优的区间的左右端点-(洛谷 小白逛公园 升级版)
"Ray, Pass me the dishes!" UVA - 1400 题意就是线段树区间子段最大和,线段树区间合并,但是这道题还要求输出最大和的子段的左右端点.要求字典序最小 ...
- Java Web开发——JSP基本语法杂记
在一个JSP页面中,可以包括指令标识.HTML代码.JavaScript代码.嵌入的Java代码.注释和JSP动作标识等内容.但是这些并不是JSP页面所必须的. 1 指令标识指令标识主要用于设定整个J ...
- cloudstack ssvm 管理地址不够造成无法启动修复过程
cloudstack日志记录: 上面已经提示了,管理ip没有了,造成这个原因很多,遇到过ssvm非正常关闭就有可能不释放IP慢慢把IP消耗掉.总之这肯定是BUG.按照上面的提示找到对应pod 和dc ...
- Linux下对拍脚本
使用说明: 1. 被测代码.正确代码.生成器代码均使用文件输入输出: 2. 对拍前会清屏,请注意: 3. 输出文件的文件名请和代码文件名保持一致: 4. 若无 ...
- [BZOJ4009][HNOI2015]接水果(整体二分)
[HNOI2015]接水果 时间限制:60s 空间限制:512MB 题目描述 风见幽香非常喜欢玩一个叫做 osu!的游戏,其中她最喜欢玩的模式就是接水果. 由于她已经DT FC 了The b ...
- 【树形DP】BZOJ1596-[Usaco2008 Jan]电话网络
[题目大意] 在一棵有n个节点的树上建信号塔,每个节点的信号塔可以覆盖当前节点极其相连的节点.问要覆盖所有节点,至少需要多少座信号塔? [思路] 经典的树形DP,直接复制一下. f[i][0]:以i为 ...
- vmware10上三台虚拟机的Hadoop2.5.1集群搭建
由于官方版本的Hadoop是32位,若在64位Linux上安装,则必须先重新在64位环境下编译Hadoop源代码.本环境采用编译后的hadoop2.5.1 . 安装参考博客: 1 http://www ...
- <form> 标签 // HTML 表单 // from 表单转换成json 格式
<form> 标签 // HTML 表单 // from 表单转换成json 格式 form 表单,对开发人员来说是在熟悉不过的了,它是页面与web服务器交互时的重要信息来源 表 ...
- Shell脚本:“syntax error:unexpected end of file”
这种错误只能说是坑,如果没有见到过,很可能就要摔里头.解决问题是重要的,但弄明白问题的来源,往往更为重要. 所以要先扯一下,换行和回车的历史遗留问题. 在计算机出现之前,有个玩意叫电传打字机.每秒钟可 ...