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
星一
ios UISegmentedControl for android

android-segmented-control Android-Segmented is a custom view for Android which is based on RadioGroup and RadioButton widget. This implementation is i

Kaopiz Software Co., Ltd. 1.9k Dec 12, 2022
ios UISegmentedControl for android

android-segmented-control Android-Segmented is a custom view for Android which is based on RadioGroup and RadioButton widget. This implementation is i

Kaopiz Software Co., Ltd. 1.9k Dec 12, 2022
A Popover Controller for Android Tablets. It's an easy solution to simulate an iOS UIPopoverController

PopoverView A Popover Controller for Android Tablets. It's an easy solution to simulate an iOS UIPopoverController Base example 9patch image comes fro

Daniel Lupiañez Casares 203 Nov 29, 2022
A realtime blurring overlay for Android (like iOS UIVisualEffectView)

RealtimeBlurView It's just a realtime blurring overlay like iOS UIVisualEffectView. Just put the view in the layout xml, no Java code is required. //

Tu Yimin 3k Jan 9, 2023
Simple and powerful library to emulate iOS's "3D Touch" preview functionality on Android.

Android 3D Touch - PeekView iOS uses 3D Touch as a way to "peek" into full content, such as emails, pictures, web searches, etc. While they have dedic

Luke Klinker 502 Dec 29, 2022
Multiplatform UI DSL with screen management in common code for mobile (android & ios) Kotlin Multiplatform development

Mobile Kotlin widgets This is a Kotlin MultiPlatform library that provides declarative UI and application screens management in common code. You can i

IceRock Development 320 Dec 30, 2022
A Jetpack Compose library with blur, pixelate, and other effects to keep your designer happy. Inspired by iOS UIVisualEffectView.

A Jetpack Compose library with blur, pixelate, and other effects to keep your designer happy. Inspired by iOS UIVisualEffectView.

清茶 67 Dec 30, 2022
Android library used to create an awesome Android UI based on a draggable element similar to the last YouTube graphic component.

Draggable Panel DEPRECATED. This project is not maintained anymore. Draggable Panel is an Android library created to build a draggable user interface

Pedro Vicente Gómez Sánchez 3k Dec 6, 2022
TourGuide is an Android library that aims to provide an easy way to add pointers with animations over a desired Android View

TourGuide TourGuide is an Android library. It lets you add pointer, overlay and tooltip easily, guiding users on how to use your app. Refer to the exa

Tan Jun Rong 2.6k Jan 5, 2023
Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your development.

Bubbles for Android Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your

Txus Ballesteros 1.5k Jan 2, 2023
View that imitates Ripple Effect on click which was introduced in Android L (for Android 2.3+)

RippleView View that imitates Ripple Effect on click which was introduced in Android L. Usage For a working implementation, Have a look at the Sample

Muthuramakrishnan Viswanathan 1.2k Dec 30, 2022
A new canvas drawing library for Android. Aims to be the Fabric.js for Android. Supports text, images, and hand/stylus drawing input. The library has a website and API docs, check it out

FabricView - A new canvas drawing library for Android. The library was born as part of a project in SD Hacks (www.sdhacks.io) on October 3rd. It is cu

Antwan Gaggi 1k Dec 13, 2022
MarkdownView is an Android webview with the capablity of loading Markdown text or file and display it as HTML, it uses MarkdownJ and extends Android webview.

About MarkdownView (Markdown For Android) is an Android library that helps you display Markdown text or files (local/remote) as formatted HTML, and st

Feras Alnatsheh 1k Dec 20, 2022
SwipeBack for Android Activities to do pretty the same as the android "back-button" will do, but in a really intuitive way by using a swipe gesture

SwipeBack SwipeBack is for Android Activities to do pretty the same as the android "back-button" will do, but in a really intuitive way by using a swi

Hannes Dorfmann 697 Dec 14, 2022
A backport of the SwitchPreference component that was introduced on Android 4 (ICS / level 14). This port works on Android 2.1+ (Eclair MR1 / level 7).

Android Switch Preference Backport A backport of the SwitchPreference component that was introduced on Android 4 (ICS / level 14). This port works on

Benoit Lubek 498 Dec 29, 2022
Wizard Pager is a library that provides an example implementation of a Wizard UI on Android, it's based of Roman Nurik's wizard pager (https://github.com/romannurik/android-wizardpager)

Wizard Pager Wizard Pager is a library that provides an example implementation of a Wizard UI on Android, it's based of Roman Nurik's wizard pager (ht

Julián Suárez 520 Nov 11, 2022
Make your native android Toasts Fancy. A library that takes the standard Android toast to the next level with a variety of styling options. Style your toast from code.

FancyToast-Android Prerequisites Add this in your root build.gradle file (not your module build.gradle file): allprojects { repositories { ... ma

Shashank Singhal 1.2k Dec 26, 2022
Make your native android Dialog Fancy. A library that takes the standard Android Dialog to the next level with a variety of styling options. Style your dialog from code.

FancyAlertDialog-Android Prerequisites Add this in your root build.gradle file (not your module build.gradle file): allprojects { repositories { ..

Shashank Singhal 350 Dec 9, 2022