iOS UIActionSheet for Android

Overview

ActionSheet

Android Arsenal Download

This is like iOS UIActionSheet component, has iOS6 and iOS7 style, support custom style, background, button image, text color and spacing etc.

Screenshot    Screenshot

Usage

Add dependency

dependencies {
    compile 'com.baoyz.actionsheet:library:1.1.7'
}

Create ActionSheet and show

ActionSheet.createBuilder(this, getSupportFragmentManager())
				.setCancelButtonTitle("Cancel")
				.setOtherButtonTitles("Item1", "Item2", "Item3", "Item4")
				.setCancelableOnTouchOutside(true)
				.setListener(this).show();

Methods

  • setCancelButtonTitle() Cancel button title, (String)
  • setOtherButtonTitles() Item buttons title,(String[])
  • setCancelableOnTouchOutside() Touch outside to close, (boolean)
  • setListener() set a Listener to listen event
  • show() Show ActionSheet, return ActionSheet Object,call dismiss() method of ActionSheet to close.

Listen event

implementing ActionSheetListener interface.

  • onOtherButtonClick() Click item event,index is item index.
  • onDismiss() Dismiss event.
   	@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

Default style is bad,ActionSheet has iOS6 and iOS7 style,you can configure the theme.

<!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <item name="actionSheetStyle">@style/ActionSheetStyleiOS6</item>
        or
        <item name="actionSheetStyle">@style/ActionSheetStyleiOS7</item>
    </style>

You can custom style, can refer to ActionSheetStyleiOS6/ActionSheetStyleiOS7 writing.

 <!-- iOS7 Style -->
 <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 attributes

  • actionSheetBackground
  • cancelButtonBackground
  • otherButtonTopBackground
  • otherButtonMiddleBackground
  • otherButtonBottomBackground
  • otherButtonSingleBackground
  • cancelButtonTextColor
  • otherButtonTextColor
  • actionSheetPadding
  • otherButtonSpacing
  • cancelButtonMarginTop
  • actionSheetTextSize
Comments
  • java.lang.IllegalStateException: Activity has been destroyed

    java.lang.IllegalStateException: Activity has been destroyed

    java.lang.IllegalStateException: Activity has been destroyed at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1399) at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:637) at android.support.v4.app.BackStackRecord.commitAllowingStateLoss(BackStackRecord.java:620) at com.talkweb.cloudcampus.view.ActionSheet.show(ActionSheet.java:65) at com.talkweb.cloudcampus.view.ActionSheet$Builder.show(ActionSheet.java:484) at com.talkweb.cloudcampus.jsbridge.WebActivity.selectImage(WebActivity.java:477) at com.talkweb.cloudcampus.jsbridge.WebActivity$CustomChromeClient.openFileChooser(WebActivity.java:343) at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:859) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4829) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) at dalvik.system.NativeStart.main(Native Method)

    已将ActionSheet的show方法中讲commit改为commitAllowingStateLoss,不知为何出现这样的报错?

    opened by HolenZhou 9
  • Update ActionSheet.java

    Update ActionSheet.java

    Referenced from http://stackoverflow.com/questions/14177781/java-lang-illegalstateexception-can-not-perform-this-action-after-onsaveinstanc

    and

    http://stackoverflow.com/questions/7575921/illegalstateexception-can-not-perform-this-action-after-onsaveinstancestate-wit

    opened by brx0826 7
  • Here's my suggestions.

    Here's my suggestions.

    Here are my suggestions;

    1. I changed this part of code;
    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putBoolean(EXTRA_DISMISSED, mDismissed);
    }
    

    to

    @Override
    public void onSaveInstanceState(Bundle outState) {
    
        outState.putBoolean(EXTRA_DISMISSED, mDismissed);
    }
    

    And you didn't approve this change, right? Is this a problem? I saw they wrote on stackoverflow that this "super.onSaveInstanceState(outState);" is causing bugs from API Level 11. What is your opinion on this?

    1. Can we put the following code inside "show" function in mHandler?
       new Handler().post(new Runnable() {
           FragmentTransaction ft = manager.beginTransaction();
           ft.add(this, tag);
           ft.addToBackStack(null);
           ft.commitAllowingStateLoss();
        });
    
    opened by brx0826 6
  • 报如下异常:java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState

    报如下异常:java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState

    java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1377) at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1395) at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:637) at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:616) at com.talkweb.cloudcampus.view.ActionSheet.show(ActionSheet.java:65) at com.talkweb.cloudcampus.view.ActionSheet$Builder.show(ActionSheet.java:482) at com.talkweb.cloudcampus.ui.common.ImageViewPagerActivity.LongPress(ImageViewPagerActivity.java:128) at com.talkweb.cloudcampus.ui.common.ImageViewPagerActivity$ImagePagerAdapter$2.onLongClick(ImageViewPagerActivity.java:155) at com.talkweb.cloudcampus.view.gallery.touchview.TouchImageView$1.onLongPress(TouchImageView.java:146) at android.view.GestureDetector.dispatchLongPress(GestureDetector.java:690) at android.view.GestureDetector.access$200(GestureDetector.java:37) at android.view.GestureDetector$GestureHandler.handleMessage(GestureDetector.java:266) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:5372) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)

    很难复现的情况,不知道是不是使用方法的问题?

    opened by HolenZhou 3
  • getNavBarHeight(Context context)  bug

    getNavBarHeight(Context context) bug

    I found on the HUAWEI phone test, NavBar transparent, get to the NavaBarHeight=0(android 5.1), which is not right, it should be used to obtain the following program NavBarHeight:

    ` public int getNavBarHeight(Context context) { int navigationBarHeight = 0; Resources rs = context.getResources(); int id = rs.getIdentifier("navigation_bar_height", "dimen", "android"); if (id > 0 && checkDeviceHasNavigationBar(context)) { navigationBarHeight = rs.getDimensionPixelSize(id); }

        return navigationBarHeight;
    }
    
    private boolean checkDeviceHasNavigationBar(Context context) {
        boolean hasNavigationBar = false;
        Resources rs = context.getResources();
        int id = rs.getIdentifier("config_showNavigationBar", "bool", "android");
        if (id > 0) {
            hasNavigationBar = rs.getBoolean(id);
        }
        try {
            Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
            Method m = systemPropertiesClass.getMethod("get", String.class);
            String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys");
            if ("1".equals(navBarOverride)) {
                hasNavigationBar = false;
            } else if ("0".equals(navBarOverride)) {
                hasNavigationBar = true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    
        return hasNavigationBar;
    
    }`
    
    opened by lanyan520 1
  • Only load one item and cancel

    Only load one item and cancel

    Hi there, I tried to using this plugin with 2 button named camera and gallery. But when I invoke it, it only showed one button. Could be something wrong here. Then could we check that? Thanks a lot. Kind regards,

    opened by thandang 1
  • It will not work api level<17 ?

    It will not work api level<17 ?

    It is giving exception here for api level. i think you should give this method only in api level>=17.

    Please check here: manager.isDestroyed()

    You can write like this to avoid the problem: if(Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR2){ }else{ }

    opened by AnkurJagani 1
  • android:allowBackup should not be used in library

    android:allowBackup should not be used in library

    Error:Execution failed for task ':app:processDebugManifest'.

    Manifest merger failed : Attribute application@allowBackup value=(false) from AndroidManifest.xml:27:9-36 is also present at [com.baoyz.actionsheet:library:1.1.0] AndroidManifest.xml:12:9-35 value=(true) Suggestion: add 'tools:replace="android:allowBackup"' to element at AndroidManifest.xml:25:5-178:19 to override

    opened by lrsb 1
  • How to show the ActionSheet like QQ ?

    How to show the ActionSheet like QQ ?

    You know , in high version of Android, the menu key can't be intercepted through onKeyDown method as long press will call to show "recent task". So, do you know how to show the ActionSheet by press down the menu key and hide it when press again?

    opened by msdx 1
  • Action sheet overlapping on bottom navigation bar on lolipop devices.

    Action sheet overlapping on bottom navigation bar on lolipop devices.

    While using action sheet and testing on lolipop devices, the action sheet appears above the bottom navigation bar (eg Nexus5) and click event also taking from navigation bar. How could I use the same action sheet on lolipop devices avoiding overlapping of navigation bar and action sheet?

    opened by UmeshAndroid 1
  • I am getting crash when try to dismiss actionsheet.

    I am getting crash when try to dismiss actionsheet.

    Hello,

    I am getting this fatal exception when try to dismiss & open actionsheet several times continuously.

    Here's the full stack trace.

    Fatal Exception: java.lang.IllegalStateException Can not perform this action after onSaveInstanceState raw android.support.v4.app.FragmentManagerImpl.checkStateLoss (FragmentManager.java:1377) android.support.v4.app.FragmentManagerImpl.popBackStack (FragmentManager.java:495) com.baoyz.actionsheet.ActionSheet.dismiss (ActionSheet.java:98) com.baoyz.actionsheet.ActionSheet.onClick (ActionSheet.java:387) android.view.View.performClick (View.java:5254) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1199)

    Would you please tell me how I can get over with this issue?

    Thank you!

    opened by brx0826 0
  • How to include this style in default Action bar menu

    How to include this style in default Action bar menu

    Hi, I want to include this style in my actionbar menu Instead of, getMenuInflater().inflate(R.menu.main, menu); I even tried adding this in my style, @style/ActionSheetStyleiOS7

    Thanks in advance

    opened by sankar2389 0
Owner
星一
Read the fucking code
星一
An android custom view which looks like the menu in Path 2.0 (for iOS).

ArcMenu & RayMenu ArcMenu An android custom view which looks like the menu in Path 2.0 (for iOS). RayMenu About The user experience in Path 2.0 (for i

daCapricorn 1.3k Nov 29, 2022
An Android library that allows you to easily create applications with slide-in menus. You may use it in your Android apps provided that you cite this project and include the license in your app. Thanks!

SlidingMenu (Play Store Demo) SlidingMenu is an Open Source Android library that allows developers to easily create applications with sliding menus li

Jeremy Feinstein 11.1k Dec 21, 2022
Android-NewPopupMenu 3.9 0.0 Java is an android library to create popup menu with GoogleMusic app-like style.

Android-NewPopupMenu Android-NewPopupMenu is an android library to create popup menu with GoogleMusic app-like style. Requirements Tested with APIv4 H

u1aryz 159 Nov 21, 2022
BottomSheet-Android - A simple customizable BottomSheet Library for Android Kotlin

BottomSheet-Android A simple customizable BottomSheet Library for Android Kotlin

Munachimso Ugorji 0 Jan 3, 2022
an animated circular menu for Android

CircularFloatingActionMenu An animated, customizable circular floating menu for Android, inspired by Path app. Getting Started Requirements API >= 15

Oğuz Bilgener 2.7k Dec 24, 2022
A menu which can ... BOOM! - Android

BoomMenu 2.0.0 Comes Finally Approximately 8 months ago, I got an inspiration to creating something that can boom and show menu, which I named it Boom

Nightonke 5.8k Dec 27, 2022
Animations for Android L drawer, back, dismiss and check icons

Material Menu Morphing Android menu, back, dismiss and check buttons Have full control of the animation: Including in your project compile 'com.balysv

Balys Valentukevicius 2.5k Dec 30, 2022
Android library that provides the floating action button to sheet transition from Google's Material Design.

MaterialSheetFab Library that implements the floating action button to sheet transition from Google's Material Design documentation. It can be used wi

Gordon Wong 1.6k Dec 13, 2022
Android Satellite Menu

#Satellite Menu 'Path' has a very attractive menu sitting on the left bottom corner of the screen. Satellite Menu is the open version of this menu. Fo

Siyamed SINIR 1.4k Nov 15, 2022
DropDownMenu for Android,Filter the list based on multiple condition.

DropDownMenu DropDownMenu for Android,filter the list based on multiple condition. To get this project into your build Step 1. Add the specific reposi

Jay.Fang 808 Nov 10, 2022
(UNMAINTAINED) An implemention of Filter Menu concept for android

FilterMenu This is a library project with a custom view that implements concept of Filter Menu(https://dribbble.com/shots/1956586-Filter-Menu) made by

Lin Zhang 824 Nov 28, 2022
Navigation menu for Android (based off Google+ app)

RibbonMenu Navigation menu for Android (based on Google+ app). Usage Menus are created in xml as normal, adding text and an icon. In the layout you wa

David Scott 487 Nov 24, 2022
Simple and easy to use circular menu widget for Android.

Deprecated This project is no longer maintained. No new issues or pull requests will be accepted. You can still use the source or fork the project to

Anup Cowkur 420 Nov 25, 2022
A multicard menu that can open and close with animation on android

MultiCardMenu A multicard menu that can open and close with animation on android,require API level >= 11 Demo ##Usage <net.wujingchao.android.view.

null 562 Nov 10, 2022
Implementation of "Side Navigation" or "Fly-in app menu" pattern for Android (based on Google+ app)

Android SideNavigation Library Implementation of "Side Navigation" or "Fly-in app menu" pattern for Android (based on Google+ app). Description The Go

Evgeny Shishkin 319 Nov 25, 2022
Android - Blur Navigation Drawer like Etsy app.

Blur Navigation Drawer Library[DEPRECATED] Blur Navigation Drawer like Etsy app. Demo You can download a demo here. Updates Version 1.1 Add support fo

Vasilis Charalampakis 414 Nov 23, 2022
Simple library which enable you to add a drawer(slide-out) navigation to your android application

SimpleSideDrawer is an android library to add a drawer navigation into your android application. This library has high affinity with other libraries l

null 217 Nov 25, 2022