ActionSheetForAndroid安卓版本的ActionSheet
来源:互联网 发布:巨灵数据库 编辑:程序博客网 时间:2024/06/06 01:22
编辑推荐:稀土掘金,这是一个针对技术开发者的一个应用,你可以在掘金上获取最新最优质的技术干货,不仅仅是Android知识、前端、后端以至于产品和设计都有涉猎,想成为全栈工程师的朋友不要错过!
模仿IOS里面的UIActionSheet控件,有IOS6和IOS7两种风格,可以自定义风格,背景图片、按钮图片、文字颜色、间距等。
项目地址:https://github.com/baoyongzhang/ActionSheetForAndroid
使用方法
创建一个ActionSheet并显示
ActionSheet.createBuilder(
this
, getSupportFragmentManager())
.setCancelButtonTitle(
"Cancel"
)
.setOtherButtonTitles(
"Item1"
,
"Item2"
,
"Item3"
,
"Item4"
)
.setCancelableOnTouchOutside(
true
)
.setListener(
this
).show();
方法说明
setCancelButtonTitle()
设置取消按钮的标题setOtherButtonTitles()
设置条目,String[]setCancelableOnTouchOutside()
设置点击空白处关闭setListener()
设置事件监听器show()
返回ActionSheet
对象,可以调用ActionSheet
对象的dismiss()
方法手动关闭
事件监听
实现ActionSheetListener
接口
onOtherButtonClick()
点击某个条目,index
是条目的下标onDismiss()
关闭事件,isCancel
参数表示是否是点击取消按钮、返回键、或者点击空白处(setCancelableOnTouchOutside(true)
)
@Override
public void onOtherButtonClick(ActionSheet actionSheet, int index) {
Toast.makeText(getApplicationContext(),
"click item index = "
+ index,
0).show();
}
@Override
public void onDismiss(ActionSheet actionSheet, boolean isCancle) {
Toast.makeText(getApplicationContext(),
"dismissed isCancle = "
+ isCancle, 0).show();
}
样式
默认的样式非常丑陋,项目中提供了两种Style,可以配置Theme
<!-- Application theme. -->
<style name=
"AppTheme"
parent=
"AppBaseTheme"
>
<item name=
"actionSheetStyle"
>@style/ActionSheetStyleIOS6</item>
or
<item name=
"actionSheetStyle"
>@style/ActionSheetStyleIOS7</item>
</style>
还可以自定义样式,自定义一个style即可,可以参考ActionSheetStyleIOS6/ActionSheetStyleIOS7的写法
<!-- IOS7样式 -->
<style name=
"ActionSheetStyleIOS7"
>
<item name=
"actionSheetBackground"
>@android:color/transparent</item>
<item name=
"cancelButtonBackground"
>@drawable/slt_as_ios7_cancel_bt</item>
<item name=
"otherButtonTopBackground"
>@drawable/slt_as_ios7_other_bt_top</item>
<item name=
"otherButtonMiddleBackground"
>@drawable/slt_as_ios7_other_bt_middle</item>
<item name=
"otherButtonBottomBackground"
>@drawable/slt_as_ios7_other_bt_bottom</item>
<item name=
"otherButtonSingleBackground"
>@drawable/slt_as_ios7_other_bt_single</item>
<item name=
"cancelButtonTextColor"
>
#1E82FF</item>
<item name=
"otherButtonTextColor"
>
#1E82FF</item>
<item name=
"actionSheetPadding"
>10dp</item>
<item name=
"otherButtonSpacing"
>0dp</item>
<item name=
"cancelButtonMarginTop"
>10dp</item>
<item name=
"actionSheetTextSize"
>12sp</item>
</style>
Style属性介绍
actionSheetBackground
背景cancelButtonBackground
取消按钮背景otherButtonTopBackground
选项顶部按钮背景otherButtonMiddleBackground
选项中部按钮背景otherButtonBottomBackground
选项底部按钮背景otherButtonSingleBackground
选项只有一个的按钮背景cancelButtonTextColor
取消按钮的文字颜色otherButtonTextColor
选项按钮的文字颜色actionSheetPadding
内边距otherButtonSpacing
选项按钮的间距cancelButtonMarginTop
取消按钮顶部间距actionSheetTextSize
选项按钮文字颜色
相关文章
- ActionSheetForAndroid安卓版本的ActionSheet
- 仿qq弹出列表的actionSheet用oc ,swift2和安卓的简单实现
- 安卓的历代版本
- [ios]自定义的ActionSheet
- actionSheet imageView的边界
- ActionSheet
- ActionSheet
- 安卓第一章 了解安卓的版本
- API对应的安卓版本
- 替换 安卓工程的SDK版本
- 安卓 数据库的版本升级问题
- 发布安卓版本遇到的坑。
- 安卓应用的版本更新
- 安卓版本更新的简单Demo
- 安卓版本更新的简单Demo
- 安卓版本更新的逻辑
- api对应的安卓版本
- 安卓版本对应的API
- How to play BreakerBall game on DragonBoard 410c ?
- Java解析xml的4种经典方法
- Android 仿QQ分组管理可拖动Item的ListView(附源码)
- 为何img、input等内联元素可以设置宽、高?
- 精彩案例-悬浮在桌面上的照相机
- ActionSheetForAndroid安卓版本的ActionSheet
- hdu2063 过山车
- Android实现事件监听的三种方式
- 吝啬的国度
- 目标的设定和坚持
- 【HDU 5739】Fantasia(点双连通+dfs)
- C/C++中生成动态库和静态库的方法
- java序列化
- 解决Hadoop和Spark本地版本库不统一的问题