Java Code Examples for android.support.design.widget.Snackbar#SnackbarLayout
The following examples show how to use
android.support.design.widget.Snackbar#SnackbarLayout .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BottomNavigationBehavior.java From BottomBar with Apache License 2.0 | 6 votes |
@Override public void updateSnackbar(CoordinatorLayout parent, View dependency, View child) { if (!isTablet && dependency instanceof Snackbar.SnackbarLayout) { if (mSnackbarHeight == -1) { mSnackbarHeight = dependency.getHeight(); } if (ViewCompat.getTranslationY(child) != 0) return; int targetPadding = bottomNavHeight + mSnackbarHeight - defaultOffset; ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) dependency.getLayoutParams(); layoutParams.bottomMargin = targetPadding; child.bringToFront(); child.getParent().requestLayout(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { ((View) child.getParent()).invalidate(); } } }
Example 2
Source File: SnackbarBehavior.java From floating-text-button with Apache License 2.0 | 6 votes |
@Override public void onDependentViewRemoved( CoordinatorLayout parent, FloatingTextButton child, View dependency ) { if (dependency instanceof Snackbar.SnackbarLayout) { animation = ViewCompat.animate(child) .translationY(0f) .setInterpolator(HIDE_INTERPOLATOR) .setDuration(HIDE_DURATION); animation.start(); } super.onDependentViewRemoved(parent, child, dependency); }
Example 3
Source File: FooterBehavior.java From Expert-Android-Programming with MIT License | 5 votes |
private float getTranslationYForSnackbar(CoordinatorLayout parent, FooterLayout footerLayout) { float minOffset = 0; final List<View> dependencies = parent.getDependencies(footerLayout); for (int i = 0, z = dependencies.size(); i < z; i++) { final View view = dependencies.get(i); if (view instanceof Snackbar.SnackbarLayout && parent.doViewsOverlap(footerLayout, view)) { minOffset = Math.min(minOffset, ViewCompat.getTranslationY(view) - view.getHeight()); } } return minOffset; }
Example 4
Source File: MySnackBar.java From HideImageMaker with Apache License 2.0 | 5 votes |
public static Snackbar show(@NonNull View view, @NonNull CharSequence text, int duration, @Nullable String actionText, @Nullable View.OnClickListener listener) { Snackbar snackbar = Snackbar.make(view, text, duration); Snackbar.SnackbarLayout root = (Snackbar.SnackbarLayout) snackbar.getView(); root.setBackgroundColor(view.getContext().getResources().getColor(R.color.colorPrimaryDark)); ((TextView) root.findViewById(R.id.snackbar_text)).setTextColor(Color.WHITE); if (actionText != null && listener != null) snackbar.setAction(actionText, listener).setActionTextColor(view.getResources().getColor(R.color.md_red_500)); snackbar.show(); return snackbar; }
Example 5
Source File: FABSnackbarBehavior.java From FABsMenu with Apache License 2.0 | 5 votes |
/** * Find the {@code translation Y} value for any child Snackbar components. * * @return 0.0F if there are no Snackbar components found, otherwise returns the min offset that * the FAB component should be animated. */ private float getFabTranslationYForSnackbar(CoordinatorLayout parent, View fab) { float minOffset = 0.0F; final List<View> dependencies = parent.getDependencies(fab); for (View view : dependencies) { if (view instanceof Snackbar.SnackbarLayout && parent.doViewsOverlap(fab, view)) { minOffset = Math.min(minOffset, view.getTranslationY() - (float) view.getHeight()); } } return minOffset; }
Example 6
Source File: BottomNavigationBehavior.java From NanoIconPack with Apache License 2.0 | 5 votes |
@Override public void updateSnackbar(CoordinatorLayout parent, View dependency, View child) { if (dependency instanceof Snackbar.SnackbarLayout) { if (mSnackbarHeight == -1) { mSnackbarHeight = dependency.getHeight(); } int targetPadding = (mSnackbarHeight + child.getMeasuredHeight()); dependency.setPadding(dependency.getPaddingLeft(), dependency.getPaddingTop(), dependency.getPaddingRight(), targetPadding ); } }
Example 7
Source File: FabSpeedDialBehaviour.java From fab-speed-dial with Apache License 2.0 | 5 votes |
@Override public boolean onDependentViewChanged(CoordinatorLayout parent, FabSpeedDial child, View dependency) { if (dependency instanceof Snackbar.SnackbarLayout) { updateFabTranslationForSnackbar(parent, child, dependency); } else if (dependency instanceof AppBarLayout) { // If we're depending on an AppBarLayout we will show/hide it automatically // if the FAB is anchored to the AppBarLayout updateFabVisibility(parent, (AppBarLayout) dependency, child); } return false; }
Example 8
Source File: SnackbarUtils.java From Android-UtilCode with Apache License 2.0 | 5 votes |
/** * 为snackbar添加布局 * <p>在show...Snackbar之后调用</p> * * @param child 要添加的view * @param index 位置(the position at which to add the child or -1 to add last) * @param params 布局参数 */ public static void addView(View child, int index, ViewGroup.LayoutParams params) { Snackbar snackbar = snackbarWeakReference.get(); if (snackbar != null) { View view = snackbar.getView(); Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) view; layout.addView(child, index, params); } }
Example 9
Source File: SnackbarUtil.java From CoordinatorLayoutExample with Apache License 2.0 | 5 votes |
/** * 向Snackbar中添加view * @param snackbar * @param layoutId * @param index 新加布局在Snackbar中的位置 */ public static void SnackbarAddView(Snackbar snackbar, int layoutId, int index) { View snackbarview = snackbar.getView(); Snackbar.SnackbarLayout snackbarLayout=(Snackbar.SnackbarLayout)snackbarview; View add_view = LayoutInflater.from(snackbarview.getContext()).inflate(layoutId,null); LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); p.gravity= Gravity.CENTER_VERTICAL; snackbarLayout.addView(add_view,index,p); }
Example 10
Source File: SnackbarUtils.java From AndroidUtilCode with Apache License 2.0 | 5 votes |
/** * Add view to the snackbar. * <p>Call it after {@link #show()}</p> * * @param layoutId The id of layout. * @param params The params. */ public static void addView(@LayoutRes final int layoutId, @NonNull final ViewGroup.LayoutParams params) { final View view = getView(); if (view != null) { view.setPadding(0, 0, 0, 0); Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) view; View child = LayoutInflater.from(view.getContext()).inflate(layoutId, null); layout.addView(child, -1, params); } }
Example 11
Source File: BottomVerticalScrollBehavior.java From JD-Test with Apache License 2.0 | 5 votes |
private Snackbar.SnackbarLayout getSnackBarInstance(CoordinatorLayout parent, V child) { final List<View> dependencies = parent.getDependencies(child); for (int i = 0, z = dependencies.size(); i < z; i++) { final View view = dependencies.get(i); if (view instanceof Snackbar.SnackbarLayout) { return (Snackbar.SnackbarLayout) view; } } return null; }
Example 12
Source File: SkittleLayout.java From Skittles with MIT License | 4 votes |
@Override public void addView(View child, int width, int height) { super.addView(child, width, height); if (getChildCount() != 1 && !(child instanceof Snackbar.SnackbarLayout)) addSkittleOnTop(); }
Example 13
Source File: SnackbarUtils.java From AndroidUtilCode with Apache License 2.0 | 4 votes |
/** * Show the snackbar. * * @param isShowTop True to show the snack bar on the top, false otherwise. */ public Snackbar show(boolean isShowTop) { View view = this.view; if (view == null) return null; if (isShowTop) { ViewGroup suitableParent = findSuitableParentCopyFromSnackbar(view); View topSnackBarContainer = suitableParent.findViewWithTag("topSnackBarCoordinatorLayout"); if (topSnackBarContainer == null) { CoordinatorLayout topSnackBarCoordinatorLayout = new CoordinatorLayout(view.getContext()); topSnackBarCoordinatorLayout.setTag("topSnackBarCoordinatorLayout"); topSnackBarCoordinatorLayout.setRotation(180); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // bring to front topSnackBarCoordinatorLayout.setElevation(100); } suitableParent.addView(topSnackBarCoordinatorLayout, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); topSnackBarContainer = topSnackBarCoordinatorLayout; } view = topSnackBarContainer; } if (messageColor != COLOR_DEFAULT) { SpannableString spannableString = new SpannableString(message); ForegroundColorSpan colorSpan = new ForegroundColorSpan(messageColor); spannableString.setSpan( colorSpan, 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE ); sReference = new WeakReference<>(Snackbar.make(view, spannableString, duration)); } else { sReference = new WeakReference<>(Snackbar.make(view, message, duration)); } final Snackbar snackbar = sReference.get(); final Snackbar.SnackbarLayout snackbarView = (Snackbar.SnackbarLayout) snackbar.getView(); if (isShowTop) { for (int i = 0; i < snackbarView.getChildCount(); i++) { View child = snackbarView.getChildAt(i); child.setRotation(180); } } if (bgResource != -1) { snackbarView.setBackgroundResource(bgResource); } else if (bgColor != COLOR_DEFAULT) { snackbarView.setBackgroundColor(bgColor); } if (bottomMargin != 0) { ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) snackbarView.getLayoutParams(); params.bottomMargin = bottomMargin; } if (actionText.length() > 0 && actionListener != null) { if (actionTextColor != COLOR_DEFAULT) { snackbar.setActionTextColor(actionTextColor); } snackbar.setAction(actionText, actionListener); } snackbar.show(); return snackbar; }
Example 14
Source File: BottomNavigationBehavior.java From NanoIconPack with Apache License 2.0 | 4 votes |
@Override public boolean layoutDependsOn(CoordinatorLayout parent, V child, View dependency) { mWithSnackBarImpl.updateSnackbar(parent, dependency, child); return dependency instanceof Snackbar.SnackbarLayout; }
Example 15
Source File: FabSpeedDialBehaviour.java From fab-speed-dial with Apache License 2.0 | 4 votes |
@Override public boolean layoutDependsOn(CoordinatorLayout parent, FabSpeedDial child, View dependency) { // We're dependent on all SnackbarLayouts (if enabled) return SNACKBAR_BEHAVIOR_ENABLED && dependency instanceof Snackbar.SnackbarLayout; }
Example 16
Source File: BottomNavigationBehavior.java From BottomBar with Apache License 2.0 | 4 votes |
private void updateScrollingForSnackbar(View dependency, boolean enabled) { if (!isTablet && dependency instanceof Snackbar.SnackbarLayout) { mScrollingEnabled = enabled; } }
Example 17
Source File: FabSpeedDialBehaviour.java From fab-speed-dial with Apache License 2.0 | 4 votes |
@Override public boolean layoutDependsOn(CoordinatorLayout parent, FabSpeedDial child, View dependency) { // We're dependent on all SnackbarLayouts (if enabled) return SNACKBAR_BEHAVIOR_ENABLED && dependency instanceof Snackbar.SnackbarLayout; }
Example 18
Source File: ShrinkBehavior.java From CustomBehavior with Apache License 2.0 | 4 votes |
@Override public boolean layoutDependsOn(CoordinatorLayout parent, FloatingActionButton child, View dependency) { return dependency instanceof Snackbar.SnackbarLayout; }
Example 19
Source File: FloatingActionMenu.java From AppCompat-Extension-Library with Apache License 2.0 | 4 votes |
@Override public boolean layoutDependsOn(CoordinatorLayout parent, FloatingActionMenu child, View dependency) { // We're dependent on all SnackbarLayouts (if enabled) return SNACKBAR_BEHAVIOR_ENABLED && dependency instanceof Snackbar.SnackbarLayout; }
Example 20
Source File: SkittleLayout.java From Skittles with MIT License | 4 votes |
@Override public void addView(View child, int index) { super.addView(child, index); if (getChildCount() != 1 && !(child instanceof Snackbar.SnackbarLayout)) addSkittleOnTop(); }