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 ...
随机推荐
- C++之自己实现的String类全部
一:回顾 (1)c++中的string类是在面试中和笔试中经常考的题目: 工程代码免费下载 string类的自行实现 (2)c++中的string类和fstream类合起来是处理外部数据的利器: (3 ...
- rpm 命令|rpm 安装|rpm 卸载|rpm 使用|rpm 删除
在Linux操作系统中,有一个系统软件包,它的功能类似于Windows里面的“添加/删除程序”,但是功能又比“添加/删除程序”强很多,它就是Red Hat Package Manager(简称RPM) ...
- Identity Server 4 原理和实战(完结)_建立Angular 客户端
https://material.angular.io/ 第一部是安装angular cli --prefix=ac:前缀 --routing:默认使用路由 style=scss:样式使用scss - ...
- Lightoj1093 【线段树】
题意: 给出n个数,然后对于D区间的数求一个最大差值 思路: 区间最大最小...我居然没想到线段树... #include <bits/stdc++.h> using namespace ...
- MongoDb 创建用户以及其他版本造成的一些问题
问题:require auth data to have schema version 3 but found 1 这是可以查看如下链接: http://stackoverflow.com/quest ...
- CF364D Ghd(随机化)
另一个集合\(s\)的\(ghd\)为\(max\{gcd(s')||s'|>=0.5|s|\}\) 给定序列\(a\),求\(ghd\) 随机化算法.因为\(|s'|\geq 0.5|S|\) ...
- mysql之SQL入门与提升(四)——终结篇,函数
一.SQL Aggregate (聚合)函数 SQL Aggregate 函数计算从列中取得的值,返回一个单一的值. AVG() - 返回平均值 COUNT() - 返回行数 FIRST() - 返回 ...
- bzoj1101:[POI2007]ZAP-Queries
[POI2007]ZAP-Queries 题意简述:对于给定的整数a,b和d,有多少正整数对x,y,满足x<=a,y<=b,并且gcd(x,y)=d. Solution 很显然这是一个莫比 ...
- unicode官网 unicode码表和标准下载
- Java EE规范下载