• This repository has been archived on 25/Dec/2022
  • Stars
    star
    984
  • Rank 44,611 (Top 1.0 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created almost 9 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🚕 An Android & Kotlin library for placing and manipulating Contextual Action Bars in your UI.

Material Contextual Action Bar

Maven Central Android CI License

Material CAB allows you to implement a customizable and flexible contextual action bar in your app. The traditional stock CAB on Android is limited to being placed at the top of your Activity, and the navigation drawer cannot go over it. This library lets you choose its exact location, and a toolbar is used, allowing views to be be placed over and under it.

Table of Contents

  1. Gradle Dependency
  2. Getting Started
  3. Destroying the CAB

Gradle Dependency

Maven Central

Add Material CAB to your module's build.gradle dependencies block:

dependencies {

  implementation 'com.afollestad:material-cab:2.0.1'
}

Getting Started

This library attaches to your Activity by taking the place of a ViewStub in your Activity layout. For an example, this is similar to the main layout of the sample project:

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical">

  <FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <androidx.appcompat.widget.Toolbar
      android:id="@+id/main_toolbar"
      ... />

    <ViewStub
      android:id="@+id/cab_stub"
      android:layout_width="match_parent"
      android:layout_height="?actionBarSize" />

  </FrameLayout>

  <androidx.recyclerview.widget.RecyclerView
    android:id="@+id/list"
    ... />

</LinearLayout>

You create/attach a Material CAB in an Activity like this:

class MyActivity : AppCompatActivity() {
  private var cab: AttachedCab? = null
  
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    
    // createCab is an extension on Activity/Fragment
    cab = createCab(R.id.cab_stub) {
        title(R.string.some_title)
        menu(R.menu.some_menu)
        slideDown()
    }
  }
}

R.id.cab_stub references the ViewStub, which is replaced with the CAB toolbar.

In addition, you can also pass the ID of a ViewGroup (such as a FrameLayout). The CAB will get appended as a child to that view group.


Configuration

You can configure various properties about your CAB during attachment:

val attachedCab = createCab(R.id.cab_stub) {
    title(R.string.some_title)
    title(literal = "Some Title")
    subtitle(R.string.some_subtitle)
    subtitle(literal = "Some Subtitle")
    
    titleColor(R.color.white)
    titleColor(literal = Color.WHITE)
    subtitleColor(R.color.white)
    subtitleColor(literal = Color.WHITE)
    
    popupTheme(R.style.ThemeOverlay_AppCompat_Light)
    
    contentInsetStart(R.dimen.mcab_default_content_inset)
    contentInsetStart(literal = 52)
    
    backgroundColor(R.color.dark_gray)
    backgroundColor(literal = Color.DARK_GRAY)
    
    closeDrawable(R.drawable.close_icon)
    
    menu(R.menu.cab_menu_items)

    onCreate { cab, menu ->
      ...
    }
    onSelection { item ->
      ...
      true // allow selection?
    }
    onDestroy { cab ->
      ...
      true // allow destruction?
    }
    
    animateOnCreate { view, animator -> 
      // Animate the view with its animator.
      // See the source of fadeIn(Long) or slideDown(Long) for an example.
    }
    
    animateOnDestroy { view, animator ->
      // Animate the view with its animator.
      // See the source of fadeIn(Long) or slideDown(Long) for an example.
    }
    
    // Sets animateOnCreate and animateOnDestroy to fade the CAB. Duration is optional, 250 is default.
    fadeIn(durationMs = 250)
    
    // Sets animateOnCreate and animateOnDestroy to slide the CAB up/down. Duration is optional, 250 is default.
    slideDown(durationMs = 250)
}

Destroying the CAB

The navigation icon in your CAB toolbar (far left button) will trigger this method, but you can manually call it whenever you'd like as well:

val cab: AttachedCab? = // ...

val isDestroyed = cab.isDestroyed() // true if null or destroyed
val isActive = cab.isActive() // true if not destroyed

cab.destroy()

This will invoke the onDestroy callback. If the callback returns true, the CAB is destroyed. If the CAB replaced a ViewStub, it's hidden (GONE), otherwise it's removed from the layout.

More Repositories

1

material-dialogs

😍 A beautiful, fluid, and extensible dialogs API for Kotlin & Android.
Kotlin
19,658
star
2

aesthetic

[DEPRECATED]
Kotlin
2,001
star
3

drag-select-recyclerview

👇 Easy Google Photos style multi-selection for RecyclerViews, powered by Kotlin and AndroidX.
Kotlin
1,962
star
4

photo-affix

📷 Stitch your photos together vertically or horizontally easily!
Kotlin
1,006
star
5

assent

🙏 Android Runtime Permissions made easy and compact, for Kotlin and AndroidX. With coroutines support!
Kotlin
853
star
6

ason

[DEPRECATED]: Prefer Moshi, Jackson, Gson, or LoganSquare
Java
759
star
7

recyclical

🚀 An easy-to-use, extensible Kotlin DSL for setting up and manipulating RecyclerViews.
Kotlin
715
star
8

vvalidator

🤖 An easy to use form validator for Kotlin & Android.
Kotlin
657
star
9

mnml

📹 A minimal, beautiful screen recorder for Android.
Kotlin
652
star
10

nock-nock

🚪 Monitor and validate your websites to maintain maximum uptime.
Kotlin
377
star
11

rxkprefs

🛠 A small Kotlin library to make shared preferences easy + RxJava and Coroutines support
Kotlin
277
star
12

ulfberht

🗡️ A small but powerful & opinionated DI library. Written in Kotlin, and powered by annotation processing.
Kotlin
251
star
13

viewpagerdots

👀 Simple, compact Kotlin library for ViewPager page indicators.
Kotlin
189
star
14

date-picker

📅 Custom responsive date picker widget for Android, written in Kotlin.
Kotlin
159
star
15

library-template-android

A Kotlin + Android library template (with a sample project).
Kotlin
152
star
16

assure

A Kotlin library that makes biometric authentication quick and easy.
Kotlin
68
star
17

arctic-icon-request

An easy to use Icon Request API for Kotlin, with traditional email capabilities plus the Arctic Manager API.
Kotlin
59
star
18

library-template-jvm

A Kotlin/JVM library template (with a sample project).
Kotlin
46
star
19

af.codes

🌐 The source code of my personal website.
HTML
31
star
20

pi-feeder

My WIP Raspberry Pi auto pet feeder system.
CSS
31
star
21

pi-feeder-android

A simple client for my Pi Feeder IoT device. Used for discovery and basic setup, scheduling is left to the web dashboard.
Java
19
star
22

node-deploy

A Git and HTTP powered deployment system for Node.js apps.
JavaScript
8
star
23

web-recording-experiments

Experiments with recording audio and video from the web. This repo is incomplete, right now. I will be adding more.
JavaScript
4
star
24

trifles

JavaScript
3
star
25

color-render

JavaScript
3
star
26

afollestad

2
star