准备:

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. 23.java方法的深入

    深入: public class MethodTest05{ public static void main(String[] args){ int i=m1(ture); System.out.pr ...

  2. android 收集的一些颜色值

    <?xml version="1.0" encoding="utf-8"?> <resources> <color name=&q ...

  3. SpringMVC注解说明

    @controller 通过@controller标注即可将class定义为一个controller类. @RequestMapping value 表示需要匹配的url的格式. method 表示所 ...

  4. CS231n 2016 通关 第四章-NN 作业

    cell 1 显示设置初始化 # A bit of setup import numpy as np import matplotlib.pyplot as plt from cs231n.class ...

  5. PHPstorm相同变量标识

    setting-> plugins-> Browse Repositories 输入BrowseWordAtCaret 搜索,安装,然后重启

  6. C++ TUTORIAL - MEMORY ALLOCATION - 2016

    http://www.bogotobogo.com/cplusplus/memoryallocation.php Variables and Memory Variables represent st ...

  7. linux内核中ip,tcp等头的定义(转)

    一.MAC帧头定义 /*数据帧定义,头14个字节,尾4个字节*/typedef struct _MAC_FRAME_HEADER{ char m_cDstMacAddress[6];    //目的m ...

  8. CodeForces 524C The Art of Dealing with ATM (二分)

    题意:给定 n 种不同的钞票,然后用q个询问,问你用最多k张,最多两种不同的钞票能不能组成一个值. 析:首先如果要求的值小点,就可以用DP,但是太大了,所以我们考虑一共最多有n * k种钞票,如果每次 ...

  9. [WIP]webpack 概念

    创建: 2019/04/09 概念    入口 指示 webpack 应该使用哪个模块,来作为构建其内部依赖图的开始. 进入入口起点后,webpack 会找出有哪些模块和库是入口起点(直接和间接)依赖 ...

  10. 牛客 - 700I - Matrix Again - 二维RMQ - 二分

    https://ac.nowcoder.com/acm/contest/700/I 二维RMQ,贴个板子,注意爆内存,用char就可以了,char也可以存负数. 然后二分枚举对角线长度,理由很简单. ...