Dialog 自定义使用1

一: 布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:background="@drawable/dialog_bg">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="30dip"
android:paddingTop="10dip">
<ImageView
android:id="@+id/dialog_title_image"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/dialog_title_image"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_centerInParent="true"
android:text="Title" // 标题
android:layout_toRightOf="@id/dialog_title_image"
android:textColor="#000000"
android:textSize="30sp"/> </RelativeLayout>
<TextView
android:layout_width="fill_parent" //横线
android:layout_height="1dip"
android:background="@drawable/lins"
android:layout_marginTop="5dip"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="This is a custom dialog" //正文
android:textColor="#000000"
android:layout_marginTop="10dip"
android:layout_marginLeft="30dip"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10dip"
android:gravity="bottom|center_horizontal"
android:paddingBottom="10dip">
<Button
android:id="@+id/dialog_button_cancel"
android:layout_alignParentLeft="true"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:text="确定"/>
<Button
android:id="@+id/dialog_button_ok"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/dialog_button_cancel"
android:layout_marginLeft="35dip"
android:text="取消"/>
</RelativeLayout>
</LinearLayout>
1 ,第一步: 样式style.xml代码
<?xml version="1.0" encoding="utf-8"?>
<resources>//
<style name="Mydialog" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item><!--边框-->
<item name="android:windowIsFloating">true</item><!--是否浮现在activity之上-->
<item name="android:windowIsTranslucent">false</item><!--半透明-->
<item name="android:windowNoTitle">true</item><!--无标题-->
<item name="android:windowBackground">@color/transparent</item><!--背景透明-->
<item name="android:backgroundDimEnabled">false</item><!--模糊-->
<item name="android:layoutAnimation">@null</item> //dialog弹出时没有动画 </style>
</resources>
自定义的dialog :
public class MyDialog extends Dialog {
Context context;
public MyDialog(Context context) {
super(context);
this.context = context;
}
public MyDialog(Context context, int theme){
super(context, theme);
this.context = context;
}
@Override
protected void onCreate(Bundle savedInstanceState) { //会先调用这个方法
super.onCreate(savedInstanceState);
this.setContentView(R.layout.dialog);
}
}
第二步 :使用的时候
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//初始化一个自定义的Dialog
Dialog dialog = new MyDialog(MyDialogActivity.this,
R.style.MyDialog); //样式
dialog.show();
}
});
Dialog 自定义使用1的更多相关文章
- 通用的Dialog自定义dialog
图样:
- Android开发:使用DialogFragment实现dialog自定义布局
使用DialogFragment实现dialog的自定义布局最大的好处是可以更好控制dialog的生命周期. TestFragment的代码: public class TestFragment ex ...
- Dialog 自定义使用2(进度条)
1: 自定义的Dialog 代码: public class IphoneProgersssDialog extends Dialog { private Context context; priv ...
- Animate a custom Dialog,自定义Dialog动画
Inside res/style.xml <style name="AppTheme" parent="android:Theme.Light" /> ...
- Dialog 自定义使用3(回调点击事件)
1 , Dialog布局 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns ...
- android 自定义Dialog去除黑色边框
在自定义Dialog时显示的界面中老是有黑色的边框,下面就介绍使用style去除黑色边框方法. 首先在values/styles定义自定义样式: <style name="MyDial ...
- jQuery Dialog弹出层对话框插件
Dialog.js的相关注释已经添加,可以按照注释,进行相关样式的修改,适用于自定义的各个系统! dialog.js /** * jQuery的Dialog插件. * * @param object ...
- Android学习笔记-Dialog详解
1.对话框的使用 1.1AlertDialog的显示 简单对话框以及监听的设置:重点掌握三个按钮(也就是三上单词): PositiveButton(确认按钮);NeutralButton(忽略按钮) ...
- android dialog圆角显示及解决出现的黑色棱角.(友情提示)
http://blog.csdn.net/jj120522/article/details/7871289 最近在开发一个天气预报的app,看到一个比较不错友情提示,如下: ...
随机推荐
- iOS 当前应用或者浏览器中 唤起 手机其他应用
这种方法 是 产品很常见的需求,关键 是在info.plist URL types 设置对应属性 比如 里面 子属性 URL identifier 设置成 bundle id //设置应用指向 ...
- js实现select动态添加option
关于 select 的添加 option 应该注意的问题. 标准的做法如上也就是说,标准的做法是 s.options.add();但是如果你一定要用 s.appendChild(option);注意了 ...
- curl 监控web
[root@rhel6 ~]# curl -I -s -w "%{http_code}\n" -o /dev/null http://127.0.0.1 [root@rhel6 ~ ...
- 彻底搞懂word-break、word-wrap、white-space
原文链接: https://juejin.im/post/5b8905456fb9a01a105966b4 white-space.word-break.word-wrap(overflow-wrap ...
- 织梦dedecms 调用文章图片数功能
function BodyImgNum($aid) { global $dsql; $sql = "select aid,body from dede_addonarticle where ...
- MapReduce修改输出的文件名
MapReduce默认输出的文件名称格式如下:part-r-00000 自定义名称,比如editName,则输出的文件名称为:editName-r-0000,此方法没有彻底修改整个文件名,只修改了一部 ...
- Entity Framework 学习笔记(二)之数据模型 Model 使用过程
Entity Framework 数据模型 Model 创建的使用: 开发环境:VS2012 数据库:SQL Server 2008 Entity Framework 版本:6.12 下面是新建的 ...
- mybatis学习(四)
创建mybatis工程 工程目录: 具体步骤: 1.创建sqlMapConfig.xml文件,配置mybatis的运行环境,事物,数据源,加载mapper映射文件等. 2.创建po类(查询或者返回的属 ...
- 【python】关于函数递归使用 return 后,收到数据为 None。
在写一个辗转相除求最小公因数的程序的时候,突然发现自己不管怎么写(除了两数恰巧可以整除),return 返回的值恒为 none. 代码为此: def gcd(a,b): if a%b==0: retu ...
- Eclipse_常用技巧_03_字母大小写转换快捷键
eclipse中字母大小写转换快捷键: ctrl+shift+x 转为大写 ctrl+shift+y 转为小写