Code Monkey home page Code Monkey logo

csnackbar's Introduction

CSnackBar Download

This is a wrapper for android Snackbar. Which giving support to change Snackbar color, duration, message or even it's content view with a custom view.

csnackbar

This library contain following functions,

  • Snackbar - alert type
  • Snackbar - set custom duration
  • Snackbar - custom contentview
  • Snackbar - binding views
  • Snackbar - custom message

####Let's take a look how to add this to your project

For the android project just include the following dependency inside you build.gradle's depedency list.

Gradle

repositories {
  jcenter()
}

dependencies {
    ...
    compile 'com.chootdev:csnackbar:1.1.0'
}

if you using maven use following Maven

<dependency>
  <groupId>com.chootdev</groupId>
  <artifactId>csnackbar</artifactId>
  <version>1.0.0</version>
  <type>pom</type>
</dependency>

After setup installing lib to your project you just need only to call it using just few lines of code. It will return you a string with the results.

Usage

To show sample Snackbar

Snackbar.with(this,null)
        .type(Type.SUCCESS)
        .message("Profile updated successfully!")
        .duration(Duration.SHORT)
        .show();

This contain multiple pre-defined types as alert view background.

Type.SUCCESS  // Green color alert to show ok, success, approved type functions
Type.ERROR    // Red color alert to show error, failer type functions
Type.UPDATE   // Grey color alert to show update take place, working type functions
Type.WARNING  // Orange color alert to show alert type functions

Type.CUSTOM   // This can use to set custom color as background

Let's take a look, how to set custom color as background

Snackbar.with(this,null)
        .type(Type.CUSTOM, 0xff00A7A5)
        .message("This is custom color!")
        .duration(Duration.LONG)
        .show();

We can use either pre-defined durations or custom duration as follow,

Duration.SHORT      // Show period of time
Duration.LONG       // Long time ( not more than 10 sec )
Duration.INFINITE   // Snackbar stay until we call dismiss

Duration.CUSTOM     // Use to set custom duration

Let's see how to a custom view to the Snackbar view

View view = getLayoutInflater().inflate(R.layout.custom_view, null);

Snackbar.with(this,null)
        .type(Type.UPDATE)
        .contentView(view, 76)
        .duration(Duration.SHORT)
        .show();
        
// since this is a wrapper lib, we need to send your custom view (layout resource) height in "dp", when setting view to the Snackbar.

When you are using custom view, you can/need to, change any view's settings before you set it as custom view to the Snackbar.

i.e :

View view = getLayoutInflater().inflate(R.layout.custom_view, null);

TextView tv = (TextView) view.findViewById(R.id.sample);

Limitations

  • Currently min SDK is set to 16

Output Generated

ezgif com-video-to-gif

Changelog

  • 1.1.0
    • Fixed snackbar long value
  • 1.0.0
    • Stable the release with sample code
  • 0.0.1
    • Initial release

Author

Chathura Hettiarachchi, [email protected]

Checkout my other contributions, https://github.com/ChathuraHettiarachchi?tab=repositories

License

Copyright 2016 Chathura Hettiarachchi

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.

csnackbar's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.