Android仿ios底部弹出框效果
准备:
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底部弹出框效果的更多相关文章
- Android仿IOS底部弹出选择菜单ActionSheet
使用Dialog的实现方式,解决原ActionSheet使用Fragment实现而出现的部分手机取消按钮被遮盖的问题 java部分代码: import android.app.Dialog; impo ...
- 仿iOS底部弹出popUpWindow
上面为弹出来的效果 popUpWindow布局: <?xml version="1.0" encoding="utf-8"?> <Linear ...
- Android仿微信进度弹出框的实现方法
MainActivity: package com.ruru.dialogproject; import android.app.Activity; import android.os.Bundle; ...
- 通用的popupwindow底部弹出框
前段时间做项目的时候,有几个底部弹出框,当时因为忙着赶进度所有就单独写了好几个popupwindow.后来就想着怎么实现一个通用的PopupWindow工具类 就是在要用到的时候创建该工具类的对象,并 ...
- UIActionSheet底部弹出框
<底部弹出框来提示用户信息> 1.遵循代理方法<UIActionSheetDelete> 2.调用放法 [UIActionSheet *sheet=[UIActio ...
- 代码录播:jQueryMobile 实现一个简单的弹出框效果
今天给大家带来的是 jQueryMobile 实现一个简单的弹出框效果,有兴趣的童鞋可以试试哦~ ^_^ 阅读原文:www.gbtags.com
- Bootboxjs快速制作Bootstrap的弹出框效果
Bootboxjs是一个简单的js库,简单快捷帮你制作一个Bootstrap的弹出框效果. 一.简介 bootbox.js是一个小的JavaScript库,它帮助您在使用bootstrap框架的时候快 ...
- Android BottomSheet:底部弹出Fragment面板(4)
Android BottomSheet:底部弹出Fragment面板(4) BottomSheet不仅可以弹出轻量级的定制好的面板(见附录文章5,6,7),还可以弹出"重"的 ...
- jquery 弹出框效果
html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <ti ...
随机推荐
- 使用Oracle数据库实现树形结构表的子-父级迭代(递归)查询和删除,通过级联菜单简单举例
前言: 我们在开发中,常常遇到单表的子-父id级联的表结构,在树形的深度不确定的情况下,一次查询出某个树形结构下的所有具有子-父级关系的数据变得十分困难. 这时,我们使用oracle提供的CONNEC ...
- 51nod 1327 棋盘游戏——延迟决策的dp
题目:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1327 因为一列填1个或0个(或0个!!!),而一行不知填多少个,所 ...
- synergy的配置使用
1.http://blog.csdn.net/qq_16618179/article/details/54094636 2.两个版本要一致 3.synergy fail to connect sec ...
- UVa 1641 ASCII Area (计算几何,水题)
题意:给定一个矩阵,里面有一个多边形,求多边形的面积. 析:因为是在格子里,并且这个多边形是很规则的,所以所有格子不是全属于多边形就是全不属于,或者一半,并且我们可以根据"/"和“ ...
- C++函数返回值与引用
对于函数的返回值,看似简单,但并非如此,比如: int func(int a);该函数会返回一个int型,如果进行一个调用int result=func(3);会发生什么情况? 首先,func将返回值 ...
- TopCoder 14084 BearPermutations2【笛卡尔树+dp】
传送:https://vjudge.net/problem/TopCoder-14084 只是利用了笛卡尔树的性质,设f[i][j]为区间[i,j]的贡献,然后枚举中间最大的点k来转移,首先是两侧小区 ...
- [Xcode 实际操作]二、视图与手势-(8)UIView视图的纹理填充
目录:[Swift]Xcode实际操作 本文将演示将导入的图片作为纹理,平铺整个屏幕. 往项目中导入一张图片. 点击底部左下角的图标->[Import]->选择需要导入的图片->[O ...
- Mycat(1)
https://www.jianshu.com/p/26513f428ecf https://blog.csdn.net/fly910905/article/details/87101059 http ...
- MVC3+jquery Uploadify 上传文件
最近做项目用到了上传图片的功能,以前也写过这类代码,不过都是用传统的file标签,今天整理一个好用的插件Uploadify..都做了一些注释,一看便知. 可以去官网下载最新的:Uploadify下载地 ...
- CF1110F Nearest Leaf
传送门 这是我第二次看见这个题目了,第一次看见是另一场比赛的A题,想了一个小时不会写就弃了 从来没想过这个题能这么玩 线段树上记录根到叶子节点的距离 初始线段树上先记下根节点1到各叶子节点的距离 先离 ...