搜索
热搜: 活动 交友 discuz
查看: 3709|回复: 0
打印 上一主题 下一主题

ActionSheetForAndroid安卓版本的ActionSheet

[复制链接]

160

主题

165

帖子

814

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
814
跳转到指定楼层
楼主
发表于 2015-12-24 17:30:13 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

模仿IOS里面的UIActionSheet控件,有IOS6和IOS7两种风格,可以自定义风格,背景图片、按钮图片、文字颜色、间距等。

项目地址:https://github.com/baoyongzhang/ActionSheetForAndroid

使用方法创建一个ActionSheet并显示[



  1. ActionSheet.createBuilder(this, getSupportFragmentManager())
  2.                 .setCancelButtonTitle("Cancel")
  3.                 .setOtherButtonTitles("Item1", "Item2", "Item3", "Item4")
  4.                 .setCancelableOnTouchOutside(true)
  5.                 .setListener(this).show();
复制代码


方法说明
  • setCancelButtonTitle()设置取消按钮的标题

  • setOtherButtonTitles()设置条目,String[]

  • setCancelableOnTouchOutside()设置点击空白处关闭

  • setListener()设置事件监听器

  • show()返回ActionSheet对象,可以调用ActionSheet对象的dismiss()方法手动关闭


事件监听
实现ActionSheetListener接口
  • onOtherButtonClick()点击某个条目,index是条目的下标

  • onDismiss()关闭事件,isCancel参数表示是否是点击取消按钮、返回键、或者点击空白处(setCancelableOnTouchOutside(true))


  1. @Override
  2.   public void onOtherButtonClick(ActionSheet actionSheet, int index) {
  3.       Toast.makeText(getApplicationContext(), "click item index = " + index,
  4.               0).show();
  5.   }
  6.   @Override
  7.   public void onDismiss(ActionSheet actionSheet, boolean isCancle) {
  8.       Toast.makeText(getApplicationContext(), "dismissed isCancle = " + isCancle, 0).show();
  9.   }
复制代码


样式
默认的样式非常丑陋,项目中提供了两种Style,可以配置Theme


  1. <!-- Application theme. -->
  2.     <style name="AppTheme" parent="AppBaseTheme">
  3.         <item name="actionSheetStyle">@style/ActionSheetStyleIOS6</item>
  4.         or
  5.         <item name="actionSheetStyle">@style/ActionSheetStyleIOS7</item>
  6.     </style>
复制代码


还可以自定义样式,自定义一个style即可,可以参考ActionSheetStyleIOS6/ActionSheetStyleIOS7的写法


  1. <!-- IOS7样式 -->
  2. <style name="ActionSheetStyleIOS7">
  3.        <item name="actionSheetBackground">@android:color/transparent</item>
  4.        <item name="cancelButtonBackground">@drawable/slt_as_ios7_cancel_bt</item>
  5.        <item name="otherButtonTopBackground">@drawable/slt_as_ios7_other_bt_top</item>
  6.        <item name="otherButtonMiddleBackground">@drawable/slt_as_ios7_other_bt_middle</item>
  7.        <item name="otherButtonBottomBackground">@drawable/slt_as_ios7_other_bt_bottom</item>
  8.        <item name="otherButtonSingleBackground">@drawable/slt_as_ios7_other_bt_single</item>
  9.        <item name="cancelButtonTextColor">#1E82FF</item>
  10.        <item name="otherButtonTextColor">#1E82FF</item>
  11.        <item name="actionSheetPadding">10dp</item>
  12.        <item name="otherButtonSpacing">0dp</item>
  13.        <item name="cancelButtonMarginTop">10dp</item>
  14.        <item name="actionSheetTextSize">12sp</item>
  15.    </style>
复制代码


Style属性介绍
  • actionSheetBackground背景

  • cancelButtonBackground取消按钮背景

  • otherButtonTopBackground选项顶部按钮背景

  • otherButtonMiddleBackground选项中部按钮背景

  • otherButtonBottomBackground选项底部按钮背景

  • otherButtonSingleBackground选项只有一个的按钮背景

  • cancelButtonTextColor取消按钮的文字颜色

  • otherButtonTextColor选项按钮的文字颜色

  • actionSheetPadding内边距

  • otherButtonSpacing选项按钮的间距

  • cancelButtonMarginTop取消按钮顶部间距

  • actionSheetTextSize选项按钮文字颜色




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|安卓论坛  

GMT+8, 2024-5-19 15:12 , Processed in 0.053580 second(s), 23 queries .

Powered by Discuz! X3.2

© 2001-2013 Design S!|ƽ̶

快速回复 返回顶部 返回列表