android怎样写一个自己定义的dialog能够在Title的位置弹出来
先上效果图:
Title的Layout为:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="@dimen/title_height"
android:background="@drawable/bg_top_title"
> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textSize="20sp"
android:layout_centerInParent="true"/> <ImageView
android:layout_width="@dimen/header_btn_width"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:layout_alignParentTop="true"
android:paddingLeft="4dp"
android:id="@+id/right_button"
android:src="@drawable/arrow_dropdown_pressed"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
弹出的dialog的Layout为
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/dropdownBckgrnd"
android:background="@drawable/bg_pop_up_dimmer"
> <ImageView
android:layout_width="@dimen/header_btn_width"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:layout_alignParentTop="true"
android:paddingLeft="4dp"
android:id="@+id/right_button"
android:src="@drawable/arrow_dropdown_pressed"
android:layout_alignParentRight="true"
/> <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_marginTop="35dp"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true"
android:background="@drawable/topmenu_popup_down"> <Button
android:layout_width="fill_parent"
android:layout_height="45dp"
android:background="@drawable/main_menu_button_background"
android:layout_margin="@dimen/button_margin_top"
android:text="aaa"
/> <Button
android:layout_width="fill_parent"
android:layout_height="45dp"
android:background="@drawable/main_menu_button_background"
android:layout_margin="@dimen/button_margin_top"
android:text="bbb"
/> <Button
android:layout_width="fill_parent"
android:layout_height="45dp"
android:background="@drawable/main_menu_button_background"
android:layout_margin="@dimen/button_margin_top"
android:text="ccc"
/>
</LinearLayout>
</RelativeLayout>
我们使用
<span style="white-space:pre"> </span>mDialog = new Dialog(context,R.style.customDialog);
mDialog.setContentView(R.layout.dialog_layout);
<style name="customDialog" parent="@android:style/Theme.Dialog">
<item name="android:windowNoTitle">true</item> //设置title
<item name="android:windowBackground">@android:color/transparent</item> //dialog应该是透明背景
<item name="android:windowIsFloating">false</item> //dialog不是悬浮的
<item name="android:layoutAnimation">@null</item> //dialog弹出时没有动画
</style>
然后我们来设置Dialog的其它属性
mDialog = new Dialog(context,R.style.customDialog);
mDialog.setContentView(R.layout.dialog_layout);
mDialog.setCanceledOnTouchOutside(true);
WindowManager.LayoutParams params = mDialog.getWindow().getAttributes();
params.gravity = Gravity.TOP;//这个设置使这个dialog从上方弹出来
params.windowAnimations = 1; WindowManager manager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
windowHeight = display.getHeight();
windowWidth = display.getWidth();
params.width = windowWidth;
params.height = windowHeight; mDialog.findViewById(R.id.right_button).setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
mDialog.dismiss();
}
}); mDialog.findViewById(R.id.dropdownBckgrnd).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mDialog.dismiss();
}
});
android怎样写一个自己定义的dialog能够在Title的位置弹出来的更多相关文章
- python递归练习:生成一个n级深度的字典,例如:[1,2,3,4,5,6] 可以生成{1: {2: {3: {4: {6: 5}}}}},写一个函数定义n级
结果#encoding = utf-8#题目:#生成一个n级深度的字典,例如:[1,2,3,4,5,6] 可以生成{1: {2: {3: {4: {6: 5}}}}},写一个函数定义n级a=[1,2, ...
- Android 自己写一个打开图片的Activity
根据记忆中eoe的Intent相关视频,模仿,写一个打开图片的Activity 1.在主Activity的button时间中,通过设置action.category.data打开一个图片.这时代码已经 ...
- android 开发 写一个RecyclerView布局的聊天室,并且添加RecyclerView的点击事件
实现思维顺序: 1.首先我们需要准备2张.9的png图片(一张图片为左边聊天泡泡,一个图片为右边的聊天泡泡),可以使用draw9patch.bat工具制作,任何图片导入到drawable中. 2.需要 ...
- 写一个自己定义进度颜色和圆形转动的ProgressBar(具体介绍)
先上图: 我们得自己定义ProgressBar的样式 <span style="white-space:pre"> </span><style nam ...
- 在Android 下写一个检测软件版本号 以自动升级APP 的插件
直接上图上代码: 1.插件类的编写 工程目录结构图: 代码如下: package org.apache.cordova.versionupdate; import org.apache.cordova ...
- Android学习--写一个发送短信的apk,注意布局文件的处理过程!!!
刚开始写Android程序如图发现使用了findViewById方法之后输出的话居然是null(空指针错误),也就是说这个方法没有成功.网上说这样写是在activity_main .xml去找这个ID ...
- 用android去写一个小程序
前言: 软工的一个小作业:实现"黄金分割小游戏", 需要结对编程,队友:陈乐云 共用时两天. 早期思路设计: 采用键值对的形式,以Map作为存储结构.优点:能够将数据与用户对 ...
- Android下写一个永远不会被KILL掉的进程/服务
Android 系统对于内存管理有自己的一套方法,为了保障系统有序稳定的运信,系统内部会自动分配,控制程序的内存使用.当系统觉得当前的资源非常有限的时候,为了保证一些优先级高的程序能运行,就会杀掉一些 ...
- android开发 写一个自定义形状的按键
步骤: 1.在drawable 文件夹中创建一个xml布局文件. 2.修改布局文件 3.在需要使用背景的按键中导入布局. 创建布局文件: 修改布局文件: <?xml version=" ...
随机推荐
- rootkit后门之安装流程
1.首先是获得远程服务器的root权限 2.然后下载rootkit程序,本文用到的是mafix (下载前最好把杀毒软件关掉,基本上会报毒的!) 3.开始安装 tar -xvzf mafix.tar.g ...
- META http-equiv="refresh" 实现网页自动跳转
使用说明: < HEAD> < TITLE>刷新内容< /TITLE> < META HTTP-EQUIV="REFRESH" CONTE ...
- [Algorithom] Shuffle an array
Shuffling is a common process used with randomizing the order for a deck of cards. The key property ...
- [ES6] 07. Default Value for function param
Normally, we can set default value for function param: //Here use "Hello" as default param ...
- ASPCMS不能上传2M以上大文件修改!
\admin_aspcms\editor\upload.asp修改80行左右maxattachsize=xxxxxxxx'最大上传大小,默认是2M前提是IIS上传大小已修 其他有关IIS方面的修改: ...
- java中compareTo和compare方法之比较,集合中对象的比较
前言 转自:http://www.cnblogs.com/yueliming/archive/2013/05/22/3092576.html (这里做了一些小改动) 一直一来对集合中对象的比较方案,有 ...
- .Net Framework 之 框架图
.Net Framework框架图,如下图: 它表明了这么一种编写软件的方式或者说表明了.Net平台下开发软件的思想和规范. .Net Framework框架实际只包含两部分: 1.公共语言运行时( ...
- mac os中的一些快捷键使用及基础软件安装
mac os中terminal标签页的切换 Command+Shift+{} { 切换到左边的标签页 } 切换到右边的标签页 普通键盘对应于mac下的按键: CTRL->CONTROL WIN ...
- Apple 远程推送APNS 服务
APP注册APNS流程 http://mobiforge.com/design-development/programming-apple-push-notification-services 服务器 ...
- java数据库编程:使用元数据分析数据库
databaseMetaData 使用元数据可以分析数据库基本信息,包括版本,数据库名称,或者指定表的主键. 代码实例 package 类集; import java.sql.Connection ; ...