先上效果图:

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的位置弹出来的更多相关文章

  1. 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, ...

  2. Android 自己写一个打开图片的Activity

    根据记忆中eoe的Intent相关视频,模仿,写一个打开图片的Activity 1.在主Activity的button时间中,通过设置action.category.data打开一个图片.这时代码已经 ...

  3. android 开发 写一个RecyclerView布局的聊天室,并且添加RecyclerView的点击事件

    实现思维顺序: 1.首先我们需要准备2张.9的png图片(一张图片为左边聊天泡泡,一个图片为右边的聊天泡泡),可以使用draw9patch.bat工具制作,任何图片导入到drawable中. 2.需要 ...

  4. 写一个自己定义进度颜色和圆形转动的ProgressBar(具体介绍)

    先上图: 我们得自己定义ProgressBar的样式 <span style="white-space:pre"> </span><style nam ...

  5. 在Android 下写一个检测软件版本号 以自动升级APP 的插件

    直接上图上代码: 1.插件类的编写 工程目录结构图: 代码如下: package org.apache.cordova.versionupdate; import org.apache.cordova ...

  6. Android学习--写一个发送短信的apk,注意布局文件的处理过程!!!

    刚开始写Android程序如图发现使用了findViewById方法之后输出的话居然是null(空指针错误),也就是说这个方法没有成功.网上说这样写是在activity_main .xml去找这个ID ...

  7. 用android去写一个小程序

    前言: 软工的一个小作业:实现"黄金分割小游戏", 需要结对编程,队友:陈乐云    共用时两天. 早期思路设计: 采用键值对的形式,以Map作为存储结构.优点:能够将数据与用户对 ...

  8. Android下写一个永远不会被KILL掉的进程/服务

    Android 系统对于内存管理有自己的一套方法,为了保障系统有序稳定的运信,系统内部会自动分配,控制程序的内存使用.当系统觉得当前的资源非常有限的时候,为了保证一些优先级高的程序能运行,就会杀掉一些 ...

  9. android开发 写一个自定义形状的按键

    步骤: 1.在drawable 文件夹中创建一个xml布局文件. 2.修改布局文件 3.在需要使用背景的按键中导入布局. 创建布局文件: 修改布局文件: <?xml version=" ...

随机推荐

  1. 完美解决“find: 路径必须在表达式之前:”

    使用find命令查找文件的时候会有如题的提示,只需略作修改即可.两种方法: ①可cd到其它目录再查找(当前目录下存在要查找的目标文件时会出现此类错误,换到其它目录下再执行相同的命令即可): ②如果目标 ...

  2. ORA-01219:数据库未打开:仅允许在固定表/视图中查询

    好久没有登陆到Oracle的服务器了,把密码都忘记了.sql>conn sys/sys as sysdba;sql>alter user system identified by *;结果 ...

  3. JQuery选择器中的一些注意事项

    1. 选择器中含有特殊符号的注意事项 1. 1 选择器中含有",","#","("或"]"等特殊字符 根据w3c的规定, ...

  4. 【4.29安恒杯】writeup

    #### 安恒杯_writeup 下面为比赛中做出的题目 MISC: SHOW ME THE FLAG-by-cyyzore CRYPTO: LAZYATTACK-by-GoldsNow 这一题非常巧 ...

  5. java 过滤器(理解二)

    request.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf ...

  6. Unity3D优化之合并网格

    原文地址点击这里

  7. openerp js调用Python类方法

    转自:http://blog.csdn.net/kuaileboy1989/article/details/42875497 js调用.py文件中定义的类 形式如下: //创建product.prod ...

  8. 安卓Camera APP

    一.Camera package android.hardware            该类用于设定图像捕获设置,开启/关闭预览,抓拍图片以及获取帧用于编码视频.这个类是Camera服务的客户端,用 ...

  9. Oracle 导入导出SQL 查看登录用户表个数

    导出 : --注意结尾不能加分号; 导入 IMP HLMARKET/HLMARKET@192.168.1.22:1521/orcl file=e:/db/HLMARKET_20150729.dmp f ...

  10. 深入annotation

    目标: 掌握@Target注释 掌握@Document注释 掌握@inherited注释 之前定义的annotation,如果没有明确声明,可以在任何地方使用: package 类集; @MyDefa ...