antonholovin / fluentsnackbar Goto Github PK
View Code? Open in Web Editor NEWTiny library that uses Android Design Support Library and lets you create and show snackbars in a fluent manner.
License: MIT License
Tiny library that uses Android Design Support Library and lets you create and show snackbars in a fluent manner.
License: MIT License
Creating a normal Snackbar looks like this
Snackbar.make(myCoordinatorLayout, R.string.some_message, Snackbar.LENGTH_SHORT).show();
Creating a FluentSnackbar looks like:
mFluentSnackbar = new FluentSnackbar(myActivity);
mFluentSnackbar.create("Text")
This limits how/where a FluentSnackbar can be used. I don't want to have to pass an Activity around. Looking at the source for FluentSnackbar, you use the passed in activity to 1.) get resources 2.) find android.R.id.content
.
Instead you can mimc Snackbar by taking in a View in the make
method. This will allow you to
mView.getContext()
)Snackbar.findSuitableParent(View view)
to find the right container to insert the Snackbar: private static ViewGroup findSuitableParent(View view) {
ViewGroup fallback = null;
do {
if (view instanceof CoordinatorLayout) {
// We've found a CoordinatorLayout, use it
return (ViewGroup) view;
} else if (view instanceof FrameLayout) {
if (view.getId() == android.R.id.content) {
// If we've hit the decor content view, then we didn't find a CoL in the
// hierarchy, so use it.
return (ViewGroup) view;
} else {
// It's not the content view but we'll use it as our fallback
fallback = (ViewGroup) view;
}
}
if (view != null) {
// Else, we will loop and crawl up the view hierarchy and try to find a parent
final ViewParent parent = view.getParent();
view = parent instanceof View ? (View) parent : null;
}
} while (view != null);
// If we reach here then we didn't find a CoL or a suitable content view so we'll fallback
return fallback;
}
How to use this lib in common Activity
.
Can't use this in none Theme.AppCompat
.
So, any idea for me?
show()
should return the Snackbar instance. Without it it's impossible to dismiss the current Snackbar if the same has a LENGTH_INDEFINITE
duration.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.