Coder Social home page Coder Social logo

tsnackbar's Introduction

Top Snackbar

Looking for a contributor here, because I don't have time anymore to take care of this.

Android Arsenal

Show a Snackbar from the top. A big thanks to https://github.com/ejohansson, https://github.com/antoninovitale, https://github.com/hansonchris and everyone that took the time to make pull requests.

alt text

Icons support:

alt text

Installation (app's build.gradle):

maven {
            url 'https://jitpack.io'
        }

implementation 'com.github.Redman1037:TSnackBar:V2.0.0'

How to use it (a tutorial starting from simple usage to complex one):

Example 1: Simple usage:
TSnackbar.make(findViewById(android.R.id.content),"Hello from TSnackBar.",TSnackbar.LENGTH_LONG).show();
Example 2: Custom colors:
TSnackbar snackbar = TSnackbar.make(findViewById(android.R.id.content), "A Snackbar is a lightweight material design method for providing feedback to a user, while optionally providing an action to the user.", TSnackbar.LENGTH_LONG);
snackbar.setActionTextColor(Color.WHITE);
View snackbarView = snackbar.getView();
snackbarView.setBackgroundColor(Color.parseColor("#CC00CC"));
TextView textView = (TextView) snackbarView.findViewById(com.androidadvance.topsnackbar.R.id.snackbar_text);
textView.setTextColor(Color.YELLOW);
snackbar.show();
Example 3: Give 'em everything you got:
//vectordrawable
TSnackbar snackbar = TSnackbar
        .make(relative_layout_main, "Snacking with VectorDrawable", TSnackbar.LENGTH_LONG);
        snackbar.setActionTextColor(Color.WHITE);
        snackbar.setIconLeft(R.drawable.ic_android_green_24dp, 24);
        View snackbarView = snackbar.getView();
        snackbarView.setBackgroundColor(Color.parseColor("#CC00CC"));
        TextView textView = (TextView) snackbarView.findViewById(com.androidadvance.topsnackbar.R.id.snackbar_text);
        textView.setTextColor(Color.YELLOW);
        snackbar.show();

  //left and right icon
 TSnackbar snackbar = TSnackbar
         .make(relative_layout_main, "Snacking Left & Right", TSnackbar.LENGTH_LONG);
         snackbar.setActionTextColor(Color.WHITE);
         snackbar.setIconLeft(R.mipmap.ic_core, 24); //Size in dp - 24 is great!
         snackbar.setIconRight(R.drawable.ic_android_green_24dp, 48); //Resize to bigger dp
         snackbar.setIconPadding(8);
         snackbar.setMaxWidth(3000); //if you want fullsize on tablets
         View snackbarView = snackbar.getView();
         snackbarView.setBackgroundColor(Color.parseColor("#CC00CC"));
         TextView textView = (TextView) snackbarView.findViewById(com.androidadvance.topsnackbar.R.id.snackbar_text);
         textView.setTextColor(Color.YELLOW);
         snackbar.show();

Troubleshooting

  1. Make sure you have the latest shit. At this moment: compileSdkVersion 99+, targetSdkVersion 99+, buildToolsVersion "99.0.1", compile 'com.android.support:appcompat-v7:99.1.0', compile 'com.android.support:design:99.1.0' etc.
  2. Notice that, if you use findViewById(android.R.id.content) your tsnackbar might appear over your notifications bar (the one with the clock, battery). To fix it, replace it with your view, coordinator layout etc.
  3. If your TSnackbar appears with padding on the sides, make sure the parent view doesn't have padding.
  4. Note: remember to use CoordinatorLayout if you get some strange behaviour!

Updates, Questions, and Requests

Ping me here :)

Want to contribute ?

You are a hero.

TODO://

  • Persistent mode.
  • Waiting for your suggestions

Changes List

1.1.1: added .setMaxWidth() method to make (ex: you want them to appear larger(fullwith) on tablets)

You like this library ? Check:

Stargazers over time

Stargazers over time

License

Copyright 2015 AndroidAdvance.com

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.

tsnackbar's People

Contributors

ahaverty avatar andreid avatar ejohansson avatar girlswhocodebulgaria avatar johnjohndoe avatar ligi avatar redman1037 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tsnackbar's Issues

大神您好!复杂布局不能正确弹出 看不到效果

发现个小问题 主布局是CoordinatorLayout 内层是一个AppBarLayout 和一个可滚动的控件,AppBarLayout内部是一个collapsingToolbarLayout,目前不能看到顶部弹出Snackbar的效果,看不到效果,不知道是不是第一个参数给的有问题 我给的是最外层的协调器布局。

Possible restructure

Hi,

I have forked and restructured the entire codebase at: https://github.com/coddo/TSnackBar.

I needed to do this in order to translate it as component in C# (Xamarin Android). If you like the way I structured the code, let me know so I can create a pull request.

Allow a Drawable to be set as an icon

I use Android-Icons for a lot of my icons and when trying to use Tsnackbar and setting an icon a DrawableRes is expected. However none of the images are a Resource image and are returned as Drawable.

Support VectorDrawable

It would be nice if you could support the use of VectorDrawables.

java.lang.ClassCastException: android.graphics.drawable.VectorDrawable cannot be cast to android.graphics.drawable.BitmapDrawable
                                                                 at com.androidadvance.topsnackbar.TSnackbar.addIcon(TSnackbar.java:151)

Create AAR ot JAR file.

Hi,

Can you provide the AAR file or JAR file so that I can implement cause we got our own gradle tool and need to migration with the AAR or JAR file.

I already try to get the .aar generate by rebuild in android studio but it's not working.

Solution to the redisplay bug

I found out about this lib on stack overflow, where it mentioned a bug that I ran in to. It will show the snackbar the first time but if you dismiss and show it again it wont work. The solution I found was to simply create a new one every time you want to show it. Works like a charm.

Personally, I think that it should have been written so that it could be either a top or a bottom snackbar. Also, the ability to completely customize the layout. Great work though!

Possible persistence

Is there a way to make TSnackBar persist through activity changes? Similar to the behaviour of Toasts? Perhaps making it live in the app context?

Manifest merger issue

Hi,
I am using your library in my project, but I am facing an issue with the Manifest merger, which complains about conflicting attributes in my main Manifest file and the manifest of your library.

I would like to suggest to remove all attributes from the application tag in the manifest and leave it empty. That would be sufficient for resolving such issues when adding the library as gradle dependency in other projects.

Thanks,
Tsvetan

Show TSnackBar bellow statusBar

I have a problem, because where I need to use the snackbar I do not have the view, so I'm using the native view of android that is this: findViewById(android.R.id.content), however it is appearing on under the statusbar , Is it possible to show it below the statusbar with android.R.id.content?

Optional Duration Times

Duration Time must be changeable.
I want to show it for 5000 MS.
There must be a setter for it.

Cancel/remove Snackbar when user touch on any parts of screen

When tooltip is visible and user click on any other part of the screen say user click on button and tooltip is visible and then user click on different button is any way we can cancel or remove Snackbar instead of waiting for Snackbar duration time to get overWhen Snackbar is visible and user click on any other part of the screen say user click on button and Snackbar is visible and then user click on different button is any way we can cancel or remove Snackbar instead of waiting for tooltip duration time to get over

Specify a view instead of findSuitableParent()

Enhancement : consider a scenario where an app made for tablet may have a side-bar menu & then snackbar needs to be shown on content screen on the right, then we would be able to specify viewgroup on top of which snackbar can be shown.

Cannot be used with custom toolbar

If i use a custom toolbar....and even if I set it as setSupportActionBar the snackbar will appear over the toolbar rather than below the custom toolbar

Not Centered on Tablets

Hi there, TSnackBar goes to top left side of screen on tablets.
Did you check it on tablets?

Show snack bar above toolbar [Question ]

is it possible to show snack bar above toolbar ? can we have some custom action buttons with custom position like below text or any where ?
is it possible without passing any view it will show on top ?

Arbitrary height, font family and size?

I would like to make these taller if possible. And also change the font and font size of the text. Should I put tin a pull request? Is this still maintained?

Sometimes it does not show

I do not know why, it does not show, I setted it behind the Toolbbar. I found that when i start an activity when it is still showing on the current activity, i won't show any more. For example, I show it in LoginActivity as a test, but when I start MainActivity when it is still showing, the TSnackbar won't showing anymore. It seems that you have to wait till the current showing TSnackbar is hidden. I am an Android beginner.

Move other views by layout_dodgeInsetEdges

First of all: Thanks for the library. I really like it!

I want to move some views with the appearance of the TSnackbar using layout_dodgeInsetEdges. Currently, I can't get it to work. Does this support this at all? Do I need to use it in a specific way?

Currently i use a android.support.design.widget.CoordinatorLayout as container and apply app:layout_dodgeInsetEdges="top"to one of it's existing childs. But it doesn't get moved when the TSnackbar appears.

Any helpful advice is very much appreciated.

NullPointerException

Caused by: java.lang.NullPointerException:
Attempt to invoke virtual method 'android.content.Context android.view.ViewGroup.getContext()' on a null object reference
at com.androidadvance.topsnackbar.TSnackbar.<init>(TSnackbar.java:129)
at com.androidadvance.topsnackbar.TSnackbar.make(TSnackbar.java:138)

sometimes textview's color is not white

I'm developing an SDK using this library, it works fine (the color is white).
When I put the SDK in another project, TSnackBar's text color became black, maybe different styles cause this problem, but after trying, I still can't solve this "black text color" problem : (.
Can u give me a hint? Thank you.

Display Snackbar below android.support.v7.widget.Toolbar

Is there a way to display the TSnackbar under the android Toolbar? Your sample code contains a coordinator layout, but I use a different activity main layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/tool_bar"
        style="@style/AppTheme.CustomToolbar"/>

    <FrameLayout
        android:id="@+id/fragment_placeholder"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

fragment_placeholder is obviously a layout where I add fragments.

The problem is that it doesn't matter what view I provide to TSnackbar.make, the snackbar always appears over my Toolbar, but below the notification panel (where the battery and other stuff is displayed, as you describe in the README). I want to display the snackbar below the Toolbar so it overlays a bit of "fragment_placeholder", but nothing from "tool_bar".
I hope this is possible.

Snackbar Not Showing Below Toolbar When Toolbar is Defined in Layout

I'm creating a Toolbar in my XML and the SnackBar is appearing at the top of the screen overlapping the Toolbar rather than below it. I tried creating a view below my Toolbar and using that view as the id in TSnackbar.make(), however the snackbar still shows at the top of the screen.

Snackbar not adding newlines on large screens

Hi there,

I noticed a bug while adding the tablet UI to my existing smartphone project. Not sure if it is due to the screen resolution or something else (maybe API Level).

Smartphone (small screen) correct behaviour

API Level 23
topsnackbar_ok

Tablet (large screen) wrong behaviour

API Level 25
topsnackbar_wrong

Code

Snackbar creation

snack = TSnackbar.make(rootView, message, TSnackbar.LENGTH_INDEFINITE);

View view = snack.getView();
view.setPadding(0, 10, 0, 10);
view.setBackgroundColor(getColor(colorID));
snack.setIconLeft(iconID, 24);
 snack.setIconPadding(8);
snack.setMaxWidth(-1);

TextView textView = view.findViewById(com.androidadvance.topsnackbar.R.id.snackbar_text);
textView.setTextColor(getColor(R.color.Light_Grey));

snack.show();

strings.xml

<string name="no_connection">
        <b>Connessione assente.</b>\n Senza
        Internet questa App non funziona.
</string>

Any ideas on how to fix this?

Thank you very much for you help.

Support for Constraint Layout

I tried using this in a ConstraintLayout but it always appears at the top of my view. Its my understanding that this only works with a Coordinator Layout. Is that correct? If so is there plans to support Constraint Layout and if not is it feasible for one to submit a PR?

Include custom icon on "dismiss" button

So I was wondering if it's possible to implement a way to add a custom icon at the same place that "UNDO" is supposed to be. I was able to add an icon on the left and it was great, but I need to also add a "close" custom icon on the right side.

Thank you for this great lib, and I would appreciate if you could help me out on that.

Landscape Softkey moves view up, snackbar start is moved up

In landscape mode, when the softkey opens, and I call a snackbar, I pass in my
activity.getWindow().getDecorView().getRootView() and the view is moved up thus the snack bar starts at the top of the view bottom, and only 10% of the snackbar view is visible at the end of the animation.

React Native Wrapper Request

This is not a issue report

Since I am not able to find proper contact from your profile, I am dropping the request here. Sorry for inconvenience.

Thanks for this great library. I am using this library on native side for my react native project and I would like make a wrapper for it so that the library can be used on JS-thread without native coding.

@AndreiD Any advice or suggestion? Clear documentation will be given and all credits will be yours. Just want to contribute some to the community. Please don't hesitate to contact me through [email protected], if you have any concern about the plan.

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.