All Projects → sergivonavi → Materialbanner

sergivonavi / Materialbanner

Licence: apache-2.0
A library that provides an implementation of the banner widget from the Material design.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Materialbanner

Materialnavigationview Android
📱 Android Library to implement Rich, Beautiful, Stylish 😍 Material Navigation View for your project with Material Design Guidelines. Easy to use.
Stars: ✭ 168 (-30.29%)
Mutual labels:  material-design, material-ui, material-components
Cyanea
A theme engine for Android
Stars: ✭ 1,319 (+447.3%)
Mutual labels:  material-design, material-ui, material-components
Android Iconics
Android-Iconics - Use any icon font, or vector (.svg) as drawable in your application.
Stars: ✭ 4,916 (+1939.83%)
Mutual labels:  material-design, material-ui, material-components
Mediapicker
Easy customizable picker for all your needs in Android application
Stars: ✭ 105 (-56.43%)
Mutual labels:  material-design, material-ui, material-components
Blazormaterial
Blazor components implementing Google's Material components for web - https://material.io/components/web
Stars: ✭ 136 (-43.57%)
Mutual labels:  material-design, material-ui, material-components
Materialdrawer
The flexible, easy to use, all in one drawer library for your Android project. Now brand new with material 2 design.
Stars: ✭ 11,498 (+4670.95%)
Mutual labels:  material-design, material-ui, material-components
Slidetoact
A simple 'Slide to Unlock' Material widget for Android, written in Kotlin 📱🎨🦄
Stars: ✭ 783 (+224.9%)
Mutual labels:  material-design, material-ui, material-components
Smart Webcomponents
Web Components & Custom Elements for Professional Web Applications
Stars: ✭ 110 (-54.36%)
Mutual labels:  material-design, material-ui, material-components
Bottomsheet
BottomSheet dialog library for Android
Stars: ✭ 219 (-9.13%)
Mutual labels:  material-design, material-ui, material-components
Ibackdrop
A library to simply use Backdrop in your project (make it easy). Read more ->
Stars: ✭ 137 (-43.15%)
Mutual labels:  material-design, material-ui, material-components
Material Admin
Free Material Admin Template
Stars: ✭ 219 (-9.13%)
Mutual labels:  material-design, material-ui, material-components
Materialdesign2
A beautiful app designed with Material Design 2 using Android X.
Stars: ✭ 170 (-29.46%)
Mutual labels:  material-design, material-components
Material Components Android
Modular and customizable Material Design UI components for Android
Stars: ✭ 13,128 (+5347.3%)
Mutual labels:  material-design, material-components
Ha client
It was the first Home Assistant fully native Android client from the times when there was no any official alternatives
Stars: ✭ 166 (-31.12%)
Mutual labels:  material-design, material-ui
React Material Components Web
React wrapper of Google's Material Components Web
Stars: ✭ 184 (-23.65%)
Mutual labels:  material-design, material-components
React Ui Roundup
A one-stop-shop for comparing the features of all the best React frameworks. Useful for designers and engineers alike!
Stars: ✭ 177 (-26.56%)
Mutual labels:  material-design, material-ui
Motion Shapeofview
Explain how to use MotionLayout with ShapeOfView
Stars: ✭ 236 (-2.07%)
Mutual labels:  material-design, material-ui
Wanna
💡✔ Wanna is an implementation of a 21st-century to-do list app.
Stars: ✭ 189 (-21.58%)
Mutual labels:  material-design, material-ui
React Md
React material design - An accessible React component library built from the Material Design guidelines in Sass
Stars: ✭ 2,284 (+847.72%)
Mutual labels:  material-design, material-components
Jekyll Material Theme
A Jekyll Theme based on Material Design using Materialize.
Stars: ✭ 165 (-31.54%)
Mutual labels:  material-design, material-ui

MaterialBanner Download License Android Arsenal

A banner displays a prominent message and related optional actions.

MaterialBanner is a library that provides an implementation of the banner widget from the Material design.

Banners - Material Design.

MaterialBanner animation

Preview

MaterialBanner

You can download the sample app here.

Setup

Add the gradle dependency

implementation "com.sergivonavi:materialbanner:1.2.0"

Check your theme

In order to use this banner your app theme should inherit from a Material Components theme.

More about that: Getting Started - Material Components for Android.

Create your banner

In your layout.xml:

<com.sergivonavi.materialbanner.Banner
    android:id="@+id/banner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:visibility="gone" // don't hide if you want to show this banner everytime
    app:buttonLeftText="Dismiss"
    app:buttonRightText="Turn on wifi"
    app:icon="@drawable/ic_signal_wifi_off_40dp"
    app:messageText="You have lost connection to the Internet." />

then in your Activity/Fragment:

Banner banner = findViewById(R.id.banner);
banner.setLeftButtonListener(new BannerInterface.OnClickListener() {
    @Override
    public void onClick(BannerInterface banner) {
        // do something
    }
});
banner.setRightButtonListener(new BannerInterface.OnClickListener() {
    @Override
    public void onClick(BannerInterface banner) {
        // do something
    }
});
// show when needed
banner.show();

// and later on
banner.dismiss();

From the code using Builder:

Banner banner = new Banner.Builder(context).setParent(rootView)
    .setIcon(R.drawable.ic_signal_wifi_off_40dp)
    .setMessage("You have lost connection to the Internet. This app is offline.")
    .setLeftButton("Dismiss", new BannerInterface.OnClickListener() {
        @Override
        public void onClick(BannerInterface banner) {
            banner.dismiss();
        }
    })
    .setRightButton("Turn on wifi", new BannerInterface.OnClickListener() {
        @Override
        public void onClick(BannerInterface banner) {
            // do something
        }
    })
    .create(); // or show() if you want to show the Banner immediately
    
    ...
    
    banner.show();

DO NOT forget to call Builder#setParent(...). Pass here a ViewGroup that will be a parent for your banner.

Or you can use:

  • setParent(ViewGroup, int) to specify the index of the banner in ViewGroup's hierarchy;
  • setParent(ViewGroup, int, ViewGroup.LayoutParams) to change the default LayoutParams.

Note

You don't need to set both left and right buttons: you can set one of them (doesn't matter which one).

Additional setup

Add listeners

If you want to know when your banner was shown or dismissed you can set appropriate listeners from BannerInterface:

banner.setOnDismissListener(new BannerInterface.OnDismissListener() {
    @Override
    public void onDismiss() {
        // do something
    }
})
banner.setOnShowListener(new BannerInterface.OnShowListener() {
    @Override
    public void onShow() {
        // do something
    }
})

Or chain these calls to the Builder:

new Banner.Builder(context)
    ...
    .setOnDismissListener(new BannerInterface.OnDismissListener() {
        @Override
        public void onDismiss() {
            // do something
        }
    })
    .setOnShowListener(new BannerInterface.OnShowListener() {
        @Override
        public void onShow() {
            // do something
        }
    })
    ...

Styling

For the style guidelines read Banners - theming.

Changing style of a single banner

In your layout.xml

Available attributes:

  • backgroundColor
  • iconTint
  • messageTextAppearance
  • messageTextColor
  • buttonsTextAppearance
  • buttonsTextColor
  • buttonsRippleColor
  • lineColor
  • lineOpacity

Usage:

<com.sergivonavi.materialbanner.Banner
    ...
    app:backgroundColor="@color/custom_background"
    app:iconTint="@color/custom_icon_tint"
    app:messageTextAppearance="@style/BannerMessageTextAppearance"
    app:messageTextColor="@color/custom_message_text"
    app:buttonsTextAppearance="@style/BannerButtonsTextAppearance"
    app:buttonsTextColor="@color/custom_buttons_text"
    app:buttonsRippleColor="@color/custom_buttons_ripple"
    app:lineColor="@color/custom_line"
    app:lineOpacity="0.8" />

From the code

Available methods:

  • setBackgroundColor
  • setIconTintColor
  • setMessageTextAppearance
  • setMessageTextColor
  • setButtonsTextAppearance
  • setButtonsTextColor
  • setButtonsRippleColor
  • setLineColor
  • setLineOpacity

Usage:

banner.setBackgroundColor(ContextCompat.getColor(this, R.color.custom_background));
banner.setIconTintColor(R.color.custom_icon_tint);
banner.setMessageTextAppearance(R.style.BannerMessageTextAppearance);
banner.setMessageTextColor(R.color.custom_message_text);
banner.setButtonsTextAppearance(R.style.BannerButtonsTextAppearance);
banner.setButtonsTextColor(R.color.custom_buttons_text);
banner.setButtonsRippleColor(R.color.custom_buttons_ripple);
banner.setLineColor(R.color.custom_line);
banner.setLineOpacity(0.8f);

Global style

You can change style of your banner globally.

Add bannerStyle attribute to your theme:

<style name="CustomTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    ...
    <item name="bannerStyle">@style/CustomBanner</item>
</style>

And create your custom style (you can inherit from the provided default banner styles):

<style name="CustomBanner" parent="@style/Widget.Material.Banner">
    <!-- change what you want --> 
    <item name="messageTextAppearance">@style/BannerMessageTextAppearance</item>
    <item name="buttonsTextAppearance">@style/BannerButtonsTextAppearance</item>
    ...
</style>

<style name="BannerMessageTextAppearance" parent="TextAppearance.Banner.Message">
    <item name="android:textSize">16sp</item>
    ...
</style>

<style name="BannerButtonsTextAppearance" parent="TextAppearance.Banner.Button">
    <item name="android:textStyle">bold</item>
    ...
</style>

Change padding of the banner's content to fit your layout

If you want to do something like this: Banner in wide layout You can change the content's padding using provided attributes or methods:

  • attr: contentPaddingStart
  • attr: contentPaddingEnd
  • setContentPaddingStart
  • setContentPaddingEnd

But account for the default padding:

  • the end padding is always 16dp (a distance between the button's last character and the end edge of a banner)
  • the start padding depends on a user's device

On mobile:

  • the start padding is always 16dp regardless if icon set or not

On tablet (sw720dp):

  • the start padding depends whether icon set or not
    • if set then 16dp
    • otherwise 24dp

See Banners - specs for visualisation.

Example

  1. If the content of your screen has 32dp margin from both sides and you set an icon then you can set 16dp padding for your banner:
app:contentPaddingEnd="16dp"
app:contentPaddingStart="16dp"

or

banner.setContentPaddingStart(R.dimen.banner_content_padding);
banner.setContentPaddingEnd(R.dimen.banner_content_padding);
  1. Everything is the same but no icon:
  • for mobile devices - 16dp padding from both sides;
  • for tablets
    • 16dp end padding
    • 8dp start padding (32dp margin - 24dp margin of the message)

See the sample app for example.

Note

DO NOT set padding directly using the default padding attributes or methods. It will break the appearance of the widget.

License

Copyright 2019 Sergey Ivanov

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].