准备:

public class ActionSheet {
public interface OnActionSheetSelected {
void onClick(int whichButton);
} private ActionSheet() {
} public static Dialog showSheet(final Context context, final int layoutId,
final OnActionSheetSelected actionSheetSelected,
final OnCancelListener cancelListener) {
final Dialog dialog = new Dialog(context, R.style.ActionSheet);
final LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final LinearLayout layout = (LinearLayout) inflater.inflate(layoutId,
null);
final int cFullFillWidth = 10000;
layout.setMinimumWidth(cFullFillWidth); final Window w = dialog.getWindow();
final WindowManager.LayoutParams lp = w.getAttributes();
lp.x = 0;
final int cMakeBottom = -1000;
lp.y = cMakeBottom;
lp.gravity = Gravity.BOTTOM;
dialog.onWindowAttributesChanged(lp);
dialog.setCanceledOnTouchOutside(true);
if (cancelListener != null) {
dialog.setOnCancelListener(cancelListener);
} dialog.setContentView(layout);
dialog.show(); return dialog;
}
} <style name="ActionSheet" parent="@android:style/Theme.Dialog"> 应用: private ActionSheet.OnActionSheetSelected mOnActionSheetSelected;
private Dialog mActionSheet;

调用showGetPhotoDialog()方法:
public void onActionSheetClicked(final View view) {
mOnActionSheetSelected.onClick(view.getId());
} public void setOnSheetClicked(final ActionSheet.OnActionSheetSelected onActionSheetSelected) {
mOnActionSheetSelected = onActionSheetSelected;
} private void showGetPhotoDialog() {
mActionSheet = ActionSheet.showSheet(this, R.layout.actionsheet_dialog, getOnActionSheetClicked(), null);
} private ActionSheet.OnActionSheetSelected getOnActionSheetClicked() { return new ActionSheet.OnActionSheetSelected() { @Override
public void onClick(final int whichButton) {
switch (whichButton) {
case R.id.tv_button1: break;
 	    case R.id.tv_button2:

               break;
      case R.id.tv_calendar: 
         mActionSheet.dismiss();
break;
default:
break;
}
mActionSheet.dismiss(); }
     };
} 布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/clear"
android:orientation="vertical"
android:padding="5dp" > <TextView
android:id="@+id/tv_button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/actionsheet_top_selector"
android:clickable="true"
android:gravity="center"
android:onClick="onActionSheetClicked"
android:text="按钮1"
android:textSize="18sp" /> <TextView
android:id="@+id/tv_button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/actionsheet_bottom_selector"
android:clickable="true"
android:gravity="center"
android:onClick="onActionSheetClicked"
android:text="按钮2"
android:textColor="@color/green_title_bar"
android:textSize="18sp" /> <TextView
android:id="@+id/cancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@drawable/actionsheet_single_selector"
android:clickable="true"
android:gravity="center"
android:onClick="onActionSheetClicked"
android:text="@string/cancle"
android:textColor="@color/cancle_blue"
android:textSize="18sp" /> </LinearLayout>

Android仿ios底部弹出框效果的更多相关文章

  1. Android仿IOS底部弹出选择菜单ActionSheet

    使用Dialog的实现方式,解决原ActionSheet使用Fragment实现而出现的部分手机取消按钮被遮盖的问题 java部分代码: import android.app.Dialog; impo ...

  2. 仿iOS底部弹出popUpWindow

    上面为弹出来的效果 popUpWindow布局: <?xml version="1.0" encoding="utf-8"?> <Linear ...

  3. Android仿微信进度弹出框的实现方法

    MainActivity: package com.ruru.dialogproject; import android.app.Activity; import android.os.Bundle; ...

  4. 通用的popupwindow底部弹出框

    前段时间做项目的时候,有几个底部弹出框,当时因为忙着赶进度所有就单独写了好几个popupwindow.后来就想着怎么实现一个通用的PopupWindow工具类 就是在要用到的时候创建该工具类的对象,并 ...

  5. UIActionSheet底部弹出框

    <底部弹出框来提示用户信息>    1.遵循代理方法<UIActionSheetDelete>    2.调用放法 [UIActionSheet *sheet=[UIActio ...

  6. 代码录播:jQueryMobile 实现一个简单的弹出框效果

    今天给大家带来的是 jQueryMobile 实现一个简单的弹出框效果,有兴趣的童鞋可以试试哦~ ^_^ 阅读原文:www.gbtags.com  

  7. Bootboxjs快速制作Bootstrap的弹出框效果

    Bootboxjs是一个简单的js库,简单快捷帮你制作一个Bootstrap的弹出框效果. 一.简介 bootbox.js是一个小的JavaScript库,它帮助您在使用bootstrap框架的时候快 ...

  8. Android BottomSheet:底部弹出Fragment面板(4)

     Android BottomSheet:底部弹出Fragment面板(4) BottomSheet不仅可以弹出轻量级的定制好的面板(见附录文章5,6,7),还可以弹出"重"的 ...

  9. jquery 弹出框效果

    html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <ti ...

随机推荐

  1. uiautomator2.0框架

    1.   Uiautomator1.0 Uiautomator2.0 date 2012 2015 super class UiAutomatorTestCase InstrumentationTes ...

  2. React.js:template

    ylbtech-React.js: 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   作者:ylbtech出处:http://ylbtec ...

  3. 经验收获Linux终端下方便命令

    一.命令行日常系快捷键 如下的快捷方式非常有用,能够极大的提升你的工作效率: CTRL + U - 剪切光标前的内容 CTRL + K - 剪切光标至行末的内容 CTRL + Y - 粘贴 CTRL ...

  4. AngularJS系统学习之Directive(指令)

    本文转自https://www.w3ctech.com/topic/1612 原文作者: Nicolas Bevacqua 原文:AngularJS’ Internals In Depth, Part ...

  5. http://blog.sina.com.cn/s/blog_6145ed810102vr8k.html

    http://blog.sina.com.cn/s/blog_6145ed810102vr8k.html

  6. ORM框架SQLAlchemy学习

    一.基本介绍 以下介绍来自维基百科,自由的百科全书. SQLAlchemy是Python编程语言下的一款开源软件.提供了SQL工具包及对象关系映射(ORM)工具,使用MIT许可证发行. SQLAlch ...

  7. 【网络爬虫】【java】微博爬虫(二):如何抓取HTML页面及HttpClient使用

    一.写在前面 上篇文章以网易微博爬虫为例,给出了一个很简单的微博爬虫的爬取过程,大概说明了网络爬虫其实也就这么回事,或许初次看到这个例子觉得有些复杂,不过没有关系,上篇文章给的例子只是让大家对爬虫过程 ...

  8. Flutter实战视频-移动电商-48.详细页_详情和评论的切换

    48.详细页_详情和评论的切换 增加切换的效果,我们主要是修改这个地方 这样我们的评论的内容就显示出来了 最终代码 details_web.dart import 'package:flutter/m ...

  9. easyui更改messager的OkCancel按钮为(中文)确定取消

    jquery-easyui默认情况下,消息框的按钮文字是英文的OK  Cancel,但可以通过提供的方法进行修改,如: $.extend($.messager.defaults,{ ok:" ...

  10. C# 程序软件启动默认管理员权限。

    在vs的Properties目录中找到 app.manifest,将其中level="asInvoker" 改成 level="requireAdministrator& ...