├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── dictionaries
│ └── Chandru_MacBook.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ ├── values-v21
│ │ │ │ └── styles.xml
│ │ │ ├── menu
│ │ │ │ └── menu_main.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── takeoffandroid
│ │ │ │ └── customsnackbar
│ │ │ │ ├── OnActionClickListener.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── SnackBar.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── takeoffandroid
│ │ │ └── customsnackbar
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── takeoffandroid
│ │ └── customsnackbar
│ │ └── ApplicationTest.java
├── proguard-rules.pro
├── build.gradle
└── app.iml
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── LICENSE.txt
├── gradle.properties
├── CustomSnackBar.iml
├── gradlew.bat
├── README.md
└── gradlew
/.idea/.name:
--------------------------------------------------------------------------------
1 | CustomSnackBar
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
12 |
13 | How to use?
14 | -----------
15 |
16 | **To create Simple Snackbar with Title and Action text**
17 | ```
18 | SnackBar snackBar = new SnackBar();
19 | snackBar.view (view)
20 | .text ("title", "action")
21 | .show ();
22 | ```
23 | **Note:** By creating simple Snackbar, your text color will be white and action color will be yellow by default with black background.
24 |
25 | **To customize Color of Title and Action Text**
26 |
27 | ```
28 | SnackBar snackBar = new SnackBar();
29 | snackBar.view (view)
30 | .text ("title", "action")
31 | .textColors (Color.WHITE,Color.RED)
32 | .show ();
33 | ```
34 |
35 | **Tip:** You can pass your desired color codes in to
36 | `textColors(Color.WHITE,Color.RED)`.
37 |
38 | **To customize background Color of Snackbar**
39 |
40 | ```
41 | SnackBar snackBar = new SnackBar();
42 | snackBar.view (view)
43 | .text ("title", "action")
44 | .backgroundColor (Color.RED)
45 | .show ();
46 | ```
47 | **Tip:** You can pass your desired color codes as background in
48 | `backgroundColor(Color.RED)`.
49 |
50 | **To Change duration of Snackbar to be displayed**
51 |
52 | ```
53 | SnackBar snackBar = new SnackBar();
54 | snackBar.view (view)
55 | .text ("title", "action")
56 | .duration (SnackBar.SnackBarDuration.LONG)
57 | .show ();
58 | ```
59 | **Types of duration:**
60 |
61 | 1. ` SnackBar.SnackBarDuration.SHORT` - Displays Snackbar for short duration
62 |
63 | 2. ` SnackBar.SnackBarDuration.LONG` - Displays Snackbar for long duration
64 |
65 | 3. ` SnackBar.SnackBarDuration.INDEFINITE` - Snackbar disappears only if you Click Action button. This case can be used for handling any click events in a Action button ( i.e Calling any methods or changing UI's ).
66 |
67 | **Tip:** If you fail to assign your duration, by default **SHORT** duration will be assigned.
68 |
69 | **To Handle click events in Action button**
70 |
71 | ```
72 | SnackBar snackBarActionClick = new SnackBar();
73 | snackBarActionClick.view(mainContent)
74 | .text ("Error fetching data", "RETRY")
75 | .duration (SnackBar.SnackBarDuration.INDEFINITE)
76 | .setOnClickListener (true, new OnActionClickListener () {
77 | @Override
78 | public void onClick (View view) {
79 | //Do your stuffs here.
80 |
81 | }
82 | })
83 | .show ();
84 | ```
85 | **Note:** Here I have specified Snackbar duration as
86 | `SnackBar.SnackBarDuration.INDEFINITE` because to perform some actions in `onClick`
87 |
88 | Why to use CustomSnackbar?
89 | --------------------------
90 |
91 | 1. It is a better replacement for Toast, Dialogs, Alert, etc.,
92 |
93 | 2. More than that it is easy to use and enrich the User experience by easy customization through Singleton pattern.
94 |
95 | 3. It is easy to use in Activity or Fragment.
96 |
97 | > **Note:** All the above customizations are clearly explained in this sample code. Download the zip and play with Snackbar's.
98 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/app/src/main/java/com/takeoffandroid/customsnackbar/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.takeoffandroid.customsnackbar;
2 |
3 | import android.graphics.Color;
4 | import android.graphics.Typeface;
5 | import android.graphics.drawable.Drawable;
6 | import android.os.Build;
7 | import android.os.Bundle;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.view.View;
10 | import android.widget.Button;
11 | import android.widget.Toast;
12 |
13 | public class MainActivity extends AppCompatActivity implements View.OnClickListener {
14 |
15 | private Button snackTxtColor;
16 | private Button snackBgColor;
17 | private Button snackActionClick;
18 | private Button snackTitleFont;
19 | private Button snackActionFont;
20 | private Button snackTitleIcon;
21 | private Button snackActionIcon;
22 |
23 | private void findViews() {
24 | snackTxtColor = (Button)findViewById( R.id.snack_txt_color );
25 | snackBgColor = (Button)findViewById( R.id.snack_bg_color );
26 | snackActionClick = (Button)findViewById( R.id.snack_action_click );
27 | snackTitleFont = (Button)findViewById( R.id.snack_title_font );
28 | snackActionFont = (Button)findViewById( R.id.snack_action_font );
29 | snackTitleIcon = (Button)findViewById( R.id.snack_title_icon );
30 | snackActionIcon = (Button)findViewById( R.id.snack_action_icon );
31 |
32 | snackTxtColor.setOnClickListener( this );
33 | snackBgColor.setOnClickListener( this );
34 | snackActionClick.setOnClickListener( this );
35 | snackTitleFont.setOnClickListener( this );
36 | snackActionFont.setOnClickListener( this );
37 | snackTitleIcon.setOnClickListener( this );
38 | snackActionIcon.setOnClickListener( this );
39 |
40 | }
41 |
42 |
43 | @Override
44 | protected void onCreate(Bundle savedInstanceState) {
45 | super.onCreate(savedInstanceState);
46 | setContentView(R.layout.activity_main);
47 |
48 | findViews();
49 |
50 | }
51 |
52 |
53 | @Override
54 | public void onClick(View v) {
55 |
56 | switch (v.getId()){
57 |
58 | case R.id.snack_txt_color:
59 | // Handle clicks for snackTxtColor
60 |
61 | SnackBar snackBarTxtColor = new SnackBar();
62 | snackBarTxtColor.view(snackTxtColor)
63 | .text("Snackbar with custom text and action color","Done")
64 | .textColors(Color.RED,Color.GREEN)
65 | .duration(SnackBar.SnackBarDuration.SHORT)
66 | .show();
67 | break;
68 |
69 | case R.id.snack_bg_color:
70 | // Handle clicks for snackBgColor
71 |
72 | SnackBar snackBarBgColor = new SnackBar();
73 | snackBarBgColor.view(snackBgColor)
74 | .text("Snackbar with custom background color", "Done")
75 | .backgroundColor(Color.BLUE)
76 | .duration(SnackBar.SnackBarDuration.LONG)
77 | .show();
78 | break;
79 |
80 | case R.id.snack_action_click:
81 | // Handle clicks for snackActionClick
82 |
83 | SnackBar snackBarActionClick = new SnackBar();
84 | snackBarActionClick.view(snackActionClick)
85 | .text("Snackbar with ActionClick", "Click me")
86 | .duration(SnackBar.SnackBarDuration.INDEFINITE)
87 | .setOnClickListener(true, new OnActionClickListener() {
88 | @Override
89 | public void onClick(View view) {
90 |
91 | Toast.makeText(MainActivity.this,"Bye bye snackbar Toast is back",Toast.LENGTH_SHORT).show();
92 | }
93 | })
94 | .show();
95 |
96 | break;
97 |
98 | case R.id.snack_title_font:
99 |
100 | SnackBar snackBarTitleFont = new SnackBar();
101 | snackBarTitleFont.view(snackTitleFont)
102 | .text("Custom font for Title", "Done")
103 | .customTitleFont(Typeface.MONOSPACE)
104 | .show();
105 |
106 | break;
107 |
108 | case R.id.snack_action_font:
109 |
110 | SnackBar snackBarActionFont = new SnackBar();
111 | snackBarActionFont.view(snackActionFont)
112 | .text("Custom font for Action", "Done")
113 | .customActionFont(Typeface.MONOSPACE)
114 | .show();
115 |
116 | break;
117 |
118 | case R.id.snack_title_icon:
119 |
120 | SnackBar snackBarIconTitle = new SnackBar();
121 | snackBarIconTitle.view(snackTitleIcon)
122 | .text("Icons for title", "Done")
123 | .setIconForTitle(generateDrawableBasedOnVersions(), SnackBar.IconPosition.LEFT,6)
124 | .show();
125 | break;
126 |
127 | case R.id.snack_action_icon:
128 |
129 | SnackBar snackBarIconAction = new SnackBar();
130 | snackBarIconAction.view(snackActionIcon)
131 | .text("Icons for action", "Done")
132 | .setIconForAction(generateDrawableBasedOnVersions(), SnackBar.IconPosition.RIGHT,6)
133 | .show();
134 | break;
135 | }
136 | }
137 |
138 |
139 | public Drawable generateDrawableBasedOnVersions(){
140 |
141 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
142 | return getResources().getDrawable(android.R.drawable.ic_lock_lock, null);
143 | } else {
144 | return getResources().getDrawable(android.R.drawable.ic_lock_lock);
145 | }
146 | }
147 | }
148 |
--------------------------------------------------------------------------------
/app/src/main/java/com/takeoffandroid/customsnackbar/SnackBar.java:
--------------------------------------------------------------------------------
1 | package com.takeoffandroid.customsnackbar;
2 |
3 | import android.graphics.Color;
4 | import android.graphics.Typeface;
5 | import android.graphics.drawable.Drawable;
6 | import android.support.design.widget.Snackbar;
7 | import android.view.Gravity;
8 | import android.view.View;
9 | import android.widget.TextView;
10 |
11 | /**
12 | * Created by Chandru-MacBook on 10/20/15.
13 | */
14 | public class SnackBar {
15 |
16 |
17 |
18 | enum SnackBarDuration {
19 | SHORT, LONG, INDEFINITE;
20 | }
21 |
22 |
23 | enum IconPosition {
24 | LEFT, RIGHT, TOP, BOTTOM;
25 | }
26 | //Default snackbar will be showed for short duration
27 | private SnackBarDuration mSnackBarDuration = SnackBarDuration.SHORT;
28 |
29 | //Icons will be shown left by default for title
30 | private IconPosition mIconPositionTitle = IconPosition.LEFT;
31 |
32 | //Icons will be shown right by default for action
33 | private IconPosition mIconPositionAction = IconPosition.RIGHT;
34 |
35 | private OnActionClickListener mOnActionClickListener;
36 |
37 | private View mView;
38 |
39 | private String mTitleText;
40 |
41 | private String mActionText;
42 |
43 | private int mTitleTextColor = Color.WHITE;
44 |
45 | private int mActionTextColor = Color.YELLOW;
46 |
47 | private int mBackgroundColor = Color.BLACK;
48 |
49 |
50 | private Typeface mTfTitle = Typeface.DEFAULT;
51 |
52 | private Typeface mTfAction = Typeface.DEFAULT;
53 |
54 | private Drawable mTitleIconDrawable = null;
55 |
56 | private Drawable mActionIconDrawable = null;
57 |
58 | private boolean isNeedClickEvent;
59 |
60 | private int mIconTitlePadding = 0;
61 |
62 | private int mIconActionPadding = 0;
63 |
64 | //Assigning the view for which Snackbar responds
65 | public SnackBar view(View view) {
66 | this.mView = view;
67 | return this;
68 | }
69 |
70 | //Assigning the title and action text
71 |
72 | public SnackBar text(String titleText, String actionText) {
73 | this.mTitleText = titleText;
74 | this.mActionText = actionText;
75 | return this;
76 | }
77 |
78 | //To customize title and action text colors
79 |
80 | public SnackBar textColors(int titleTextColor, int actionTextColor) {
81 | this.mTitleTextColor = titleTextColor;
82 | this.mActionTextColor = actionTextColor;
83 | return this;
84 | }
85 |
86 | //To customize background color of snack bar
87 | public SnackBar backgroundColor(int backgroundColor) {
88 | this.mBackgroundColor = backgroundColor;
89 | return this;
90 | }
91 |
92 | //Change duration whether SnackBar should be shown for short, long or Indefinite
93 | public SnackBar duration(SnackBarDuration snackBarDuration) {
94 | this.mSnackBarDuration = snackBarDuration;
95 | return this;
96 | }
97 |
98 | //Change font for title
99 | public SnackBar customTitleFont(Typeface tf){
100 | this.mTfTitle = tf;
101 | return this;
102 | }
103 |
104 | //Change font for title
105 | public SnackBar customActionFont(Typeface tf){
106 | this.mTfAction = tf;
107 | return this;
108 | }
109 |
110 |
111 | public SnackBar setIconForTitle(Drawable titleDrawable, IconPosition iconPostion, int drawablePadding){
112 | this.mTitleIconDrawable = titleDrawable;
113 | this.mIconPositionTitle = iconPostion;
114 | this.mIconTitlePadding = drawablePadding;
115 | return this;
116 | }
117 |
118 | public SnackBar setIconForAction(Drawable actionDrawable, IconPosition iconPostion,int drawablePadding){
119 | this.mActionIconDrawable = actionDrawable;
120 | this.mIconPositionAction = iconPostion;
121 | this.mIconActionPadding = drawablePadding;
122 | return this;
123 | }
124 |
125 | public Snackbar getSnackBar() {
126 |
127 | int duration = 0;
128 |
129 | switch (mSnackBarDuration) {
130 |
131 | case SHORT:
132 | duration = Snackbar.LENGTH_SHORT;
133 | break;
134 |
135 | case LONG:
136 | duration = Snackbar.LENGTH_LONG;
137 | break;
138 |
139 | case INDEFINITE:
140 | duration = Snackbar.LENGTH_INDEFINITE;
141 | break;
142 | }
143 |
144 |
145 | Snackbar snackbar = Snackbar
146 | .make(mView, mTitleText, duration)
147 | .setAction(mActionText, new View.OnClickListener() {
148 | @Override
149 | public void onClick(View view) {
150 |
151 | if(isNeedClickEvent) {
152 | mOnActionClickListener.onClick(view);
153 | }
154 | }
155 | });
156 |
157 |
158 |
159 | View sbView = snackbar.getView();
160 | TextView txtTitle = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
161 | TextView txtAction = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_action);
162 |
163 | // Changing message text color
164 | txtTitle.setTextColor(mTitleTextColor);
165 |
166 |
167 | // Changing action button text color
168 | txtAction.setTextColor(mActionTextColor);
169 |
170 | //Changing background color
171 | sbView.setBackgroundColor(mBackgroundColor);
172 |
173 | //Changing font style for title
174 | txtTitle.setTypeface(mTfTitle);
175 |
176 | //Changing font style for action
177 | txtAction.setTypeface(mTfAction);
178 |
179 | setIcon(txtTitle,mTitleIconDrawable,mIconPositionTitle,Gravity.CENTER_VERTICAL, mIconTitlePadding);
180 |
181 | setIcon(txtAction,mActionIconDrawable,mIconPositionAction,Gravity.CENTER,mIconActionPadding);
182 |
183 |
184 |
185 |
186 | return snackbar;
187 | }
188 |
189 | private void setIcon(TextView textView, Drawable drawable, IconPosition iconPosition, int gravity, int iconPadding) {
190 |
191 | textView.setGravity(gravity);
192 | textView.setCompoundDrawablePadding(iconPadding);
193 | switch (iconPosition){
194 |
195 | case LEFT:
196 |
197 | textView.setCompoundDrawablesWithIntrinsicBounds(drawable,null,null,null);
198 | break;
199 |
200 | case RIGHT:
201 | textView.setCompoundDrawablesWithIntrinsicBounds(null,null,drawable,null);
202 |
203 | break;
204 |
205 | case TOP:
206 | textView.setCompoundDrawablesWithIntrinsicBounds(null,drawable,null,null);
207 |
208 | break;
209 |
210 | case BOTTOM:
211 | textView.setCompoundDrawablesWithIntrinsicBounds(null,null,null,drawable);
212 |
213 | break;
214 | }
215 | }
216 |
217 | //To show the Snackbar in UI.
218 | public void show() {
219 | getSnackBar().show();
220 | }
221 |
222 |
223 | //Listeners to handle SnackBar Action click
224 | public SnackBar setOnClickListener(boolean isNeedClickEvent, OnActionClickListener onActionClickListener){
225 |
226 | this.isNeedClickEvent = isNeedClickEvent;
227 | this.mOnActionClickListener = onActionClickListener;
228 | return this;
229 | }
230 |
231 | }
232 |
233 |
234 |
235 |
236 |
237 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |