BottomDialogs Android Library

repository·master·Indexed 20 days ago

https://github.com/javiersantos/bottomdialogs

An Android library for creating customizable, Material-based bottom sheet dialogs. It features a Builder pattern for implementing standard dialogs or custom layouts, support for icons, positive and negative buttons with callbacks, and the ability to set custom view resources.

Tokens
1.6K
Snippets
7
Records
8
Agent score
21%

What's inside BottomDialogs

  1. Install BottomDialogs via JitPack

    master

    To use BottomDialogs in your Android project, add the JitPack repository to your project-level build.gradle and then add the library dependency to your module-level build.gradle.

    // Project build.gradle
    repositories {
        maven {
            url "https://jitpack.io"
        }
    }
    
    // Module build.gradle
    dependencies {
        compile 'com.github.javiersantos:BottomDialogs:1.2.1'
    }
  2. Add buttons and callbacks to Bottom Dialog

    master

    You can add positive and negative buttons with custom text, colors, and click listeners.

    • Use .setPositiveText(String) and .setNegativeText(String) to label buttons.
    • Use .setPositiveBackgroundColorResource(int) or .setPositiveTextColorResource(int) for styling via resources.
    • Use .onPositive(BottomDialog.ButtonCallback) and .onNegative(BottomDialog.ButtonCallback) to handle clicks.

    Note on Dismissal Behavior:

    • By default, autoDismiss() is true. If you provide a callback, the dialog dismisses automatically when the button is tapped.
    • If you set autoDismiss(false), you must manually call dialog.dismiss() inside your callback.
    new BottomDialog.Builder(this)
        .setTitle("Awesome!")
        .setContent("What can we improve? Your feedback is always welcome.")
        .setPositiveText("OK")
        .setPositiveBackgroundColorResource(R.color.colorPrimary)
        .setPositiveTextColorResource(android.R.color.white)
        .onPositive(new BottomDialog.ButtonCallback() {
            @Override
            public void onClick(BottomDialog dialog) {
                Log.d("BottomDialogs", "Do something!");
            }
        }).show();
  3. Add a custom view to the Bottom Dialog

    master

    Instead of the standard title/content layout, you can provide your own layout resource using .setCustomView(int layoutResId).

    new BottomDialog.Builder(this)
        .setTitle("Awesome!")
        .setContent("What can we improve? Your feedback is always welcome.")
        .setCustomView(R.layout.my_custom_view)
        .show();
  4. Prevent dismissal when touching outside

    master

    Use .setCancelable(false) to prevent the user from dismissing the dialog by tapping the area outside the bottom sheet.

    new BottomDialog.Builder(this)
        .setTitle("Awesome!")
        .setContent("What can we improve? Your feedback is always welcome.")
        .setCancelable(false)
        .show();
  5. Display an icon in the Bottom Dialog

    master

    You can display an icon to the left of the title using the .setIcon() method. Pass a drawable resource ID.

    new BottomDialog.Builder(this)
        .setTitle("Awesome!")
        .setContent("What can we improve? Your feedback is always welcome.")
        .setIcon(R.drawable.ic_launcher)
        .show();
  6. Create a basic Bottom Dialog

    master

    Use the BottomDialog.Builder to create and show a simple dialog with a title and content. You can either call .show() directly on the builder or .build() the instance first to manipulate it later.

    // Quick way to show a dialog
    new BottomDialog.Builder(this)
        .setTitle("Awesome!")
        .setContent("What can we improve? Your feedback is always welcome.")
        .show();
    
    // Way to build and then show later
    BottomDialog bottomDialog = new BottomDialog.Builder(this)
        .setTitle("Awesome!")
        .setContent("What can we improve? Your feedback is always welcome.")
        .build();
    
    bottomDialog.show();
  7. Customize colors and fonts using View objects

    master

    For advanced styling that goes beyond the Builder, you can access the underlying Android View objects after building the dialog. This allows you to use standard TextView methods like setTextColor() or setTypeface().

    ```Java
    BottomDialog bottomDialog = BottomDialog.Builder(this)
        .setTitle("Awesome!")
        .setContent("What can we improve? Your feedback is always welcome.")
        .build();
    
    // Access views directly to apply custom styles
    bottomDialog.getTitleTextView().setTextColor(Color.parseColor("#8f000000"));
    bottomDialog.getTitleTextView().setTypeface(BaseActivity.getFont(Fonts.SEMI_BOLD));
    
    bottomDialog.show();

    Available view accessors:

    • getIconImageView()
    • getTitleTextView()
    • getContentTextView()
    • getNegativeButton()
    • getPositiveButton()