Java Code Examples for com.google.android.material.snackbar.Snackbar#getView()

The following examples show how to use com.google.android.material.snackbar.Snackbar#getView() . 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: NotificationHelper.java    From Mysplash with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void showActionSnackbar(@NonNull MysplashActivity activity,
                                      String content, String action, View.OnClickListener l) {
    View container = activity.provideSnackbarContainer();
    if (container != null) {
        Snackbar snackbar = Snackbar
                .make(container, content, Snackbar.LENGTH_LONG)
                .setAction(action, l);

        Snackbar.SnackbarLayout snackbarLayout = (Snackbar.SnackbarLayout) snackbar.getView();
        snackbarLayout.setBackgroundColor(ThemeManager.getRootColor(activity));

        TextView contentTxt = snackbarLayout.findViewById(R.id.snackbar_text);
        contentTxt.setTextColor(ThemeManager.getContentColor(activity));

        Button actionBtn = snackbarLayout.findViewById(R.id.snackbar_action);
        actionBtn.setTextColor(ThemeManager.getTitleColor(activity));

        snackbar.show();
    }
}
 
Example 2
Source File: BaseActivity.java    From Instagram-Profile-Downloader with MIT License 6 votes vote down vote up
@Override
public void showSnackBar(String message) {
    final Snackbar snackbar = Snackbar.make(findViewById(android.R.id.content), message, Snackbar.LENGTH_LONG);

    View snackbarView = snackbar.getView();
    snackbarView.setBackgroundColor(Color.WHITE);
    TextView textView = (TextView) snackbarView.findViewById(R.id.snackbar_text);
    textView.setTextColor(Color.BLACK);

    snackbar.setAction("OK", new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            snackbar.dismiss();
        }
    });
    snackbar.setActionTextColor(Color.BLACK);
    snackbar.show();
}
 
Example 3
Source File: NotificationHelper.java    From Mysplash with GNU Lesser General Public License v3.0 6 votes vote down vote up
/** <br> snackbar & toast. */

    public static void showSnackbar(String content, int duration) {
        MysplashActivity a = Mysplash.getInstance().getTopActivity();
        if (Mysplash.getInstance().getActivityCount() > 0) {
            View container = a.provideSnackbarContainer();

            Snackbar snackbar = Snackbar
                    .make(container, content, duration);

            Snackbar.SnackbarLayout snackbarLayout = (Snackbar.SnackbarLayout) snackbar.getView();

            TextView contentTxt = (TextView) snackbarLayout.findViewById(R.id.snackbar_text);
            DisplayUtils.setTypeface(a, contentTxt);

            if (Mysplash.getInstance().isLightTheme()) {
                contentTxt.setTextColor(ContextCompat.getColor(a, R.color.colorTextContent_light));
                snackbarLayout.setBackgroundResource(R.color.colorRoot_light);
            } else {
                contentTxt.setTextColor(ContextCompat.getColor(a, R.color.colorTextContent_dark));
                snackbarLayout.setBackgroundResource(R.color.colorRoot_dark);
            }

            snackbar.show();
        }
    }
 
Example 4
Source File: BaseSnack.java    From SnackEngage with MIT License 6 votes vote down vote up
@NonNull
protected Snackbar createSnackBar(@NonNull final SnackContext snackContext) {
    @SuppressWarnings("WrongConstant")
    final Snackbar snackbar = Snackbar.make(snackContext.getRootView(), titleText, duration);

    if (actionColor != null) {
        snackbar.setActionTextColor(actionColor);
    }
    if (backgroundColor != null) {
        View snackBarView = snackbar.getView();
        snackBarView.setBackgroundColor(backgroundColor);
    }

    return snackbar.setAction(actionText, new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            engage();
        }
    });
}
 
Example 5
Source File: NotificationHelper.java    From Mysplash with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void showActionSnackbar(String content, String action,
                                      int duration, View.OnClickListener l) {
    if (Mysplash.getInstance().getActivityCount() > 0) {
        MysplashActivity a = Mysplash.getInstance().getTopActivity();
        View container = a.provideSnackbarContainer();

        Snackbar snackbar = Snackbar
                .make(container, content, duration)
                .setAction(action, l);

        Snackbar.SnackbarLayout snackbarLayout = (Snackbar.SnackbarLayout) snackbar.getView();

        TextView contentTxt = (TextView) snackbarLayout.findViewById(R.id.snackbar_text);
        DisplayUtils.setTypeface(a, contentTxt);

        Button actionBtn = (Button) snackbarLayout.findViewById(R.id.snackbar_action);

        if (Mysplash.getInstance().isLightTheme()) {
            contentTxt.setTextColor(ContextCompat.getColor(a, R.color.colorTextContent_light));
            actionBtn.setTextColor(ContextCompat.getColor(a, R.color.colorTextTitle_light));
            snackbarLayout.setBackgroundResource(R.color.colorRoot_light);
        } else {
            contentTxt.setTextColor(ContextCompat.getColor(a, R.color.colorTextContent_dark));
            actionBtn.setTextColor(ContextCompat.getColor(a, R.color.colorTextTitle_dark));
            snackbarLayout.setBackgroundResource(R.color.colorRoot_dark);
        }

        snackbar.show();
    }
}
 
Example 6
Source File: MainActivity.java    From TowerCollector with Mozilla Public License 2.0 5 votes vote down vote up
private void showAllProjectsDisabledMessage() {
    Snackbar snackbar = Snackbar.make(activityView, R.string.uploader_all_projects_disabled, Snackbar.LENGTH_LONG)
            .setAction(R.string.main_menu_preferences_button, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    startPreferencesActivity();
                }
            });
    // hack for black text on dark grey background
    View view = snackbar.getView();
    TextView tv = view.findViewById(R.id.snackbar_text);
    tv.setTextColor(Color.WHITE);
    snackbar.show();
}
 
Example 7
Source File: SnackBarUtil.java    From FastLib with Apache License 2.0 5 votes vote down vote up
/**
 * 获取SnackBar视图
 *
 * @return SnackBar视图
 */
public static View getView() {
    Snackbar snackbar = mWeakReference.get();
    if (snackbar == null) {
        return null;
    }
    return snackbar.getView();
}
 
Example 8
Source File: SnackBarUtil.java    From FastLib with Apache License 2.0 5 votes vote down vote up
/**
 * 显示SnackBar
 */
public void show() {
    final View view = mParent.get();
    if (view == null) {
        return;
    }
    if (mMessageColor != DEFAULT_COLOR) {
        SpannableString spannableString = new SpannableString(mMessage);
        ForegroundColorSpan colorSpan = new ForegroundColorSpan(mMessageColor);
        spannableString.setSpan(colorSpan, 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        mWeakReference = new WeakReference<>(Snackbar.make(view, spannableString, mDuration));
    } else {
        mWeakReference = new WeakReference<>(Snackbar.make(view, mMessage, mDuration));
    }
    final Snackbar snackbar = mWeakReference.get();
    final View snackView = snackbar.getView();
    if (mBgResource != -1) {
        snackView.setBackgroundResource(mBgResource);
    } else if (mBgColor != DEFAULT_COLOR) {
        snackView.setBackgroundColor(mBgColor);
    }
    if (mBottomMargin != 0) {
        ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) snackView.getLayoutParams();
        params.bottomMargin = mBottomMargin;
    }
    if (mActionText.length() > 0 && mActionListener != null) {
        if (mActionTextColor != DEFAULT_COLOR) {
            snackbar.setActionTextColor(mActionTextColor);
        }
        snackbar.setAction(mActionText, mActionListener);
    }
    snackbar.show();
}
 
Example 9
Source File: UiUtil.java    From habpanelviewer with GNU General Public License v3.0 5 votes vote down vote up
private static void showSnackBar(View view, String text, String actionText, View.OnClickListener clickListener) {
    Snackbar sb = Snackbar.make(view, text, Snackbar.LENGTH_LONG);
    View sbV = sb.getView();
    TextView textView = sbV.findViewById(com.google.android.material.R.id.snackbar_text);
    textView.setMaxLines(3);
    if (actionText != null && clickListener != null) {
        sb.setAction(actionText, clickListener);
    }

    sb.show();
}
 
Example 10
Source File: MBaseActivity.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
public Snackbar getSnackBar(String msg) {
    if (getSnackBarView() == null) {
        return null;
    }
    Snackbar snackbar = Snackbar.make(getSnackBarView(), msg, Snackbar.LENGTH_SHORT);
    View view = snackbar.getView();
    view.setBackgroundResource(R.color.colorCardBackground);
    ((TextView) view.findViewById(R.id.snackbar_text)).setTextColor(getResources().getColor(R.color.colorTextDefault));
    return snackbar;
}
 
Example 11
Source File: MainActivity.java    From android-popular-movies-app with Apache License 2.0 5 votes vote down vote up
/**
 * When offline, show a snackbar message
 */
private void showSnackbarOffline() {
    Snackbar snackbar = Snackbar.make(
            mMainBinding.frameMain, R.string.snackbar_offline, Snackbar.LENGTH_LONG);
    // Set background color of the snackbar
    View sbView = snackbar.getView();
    sbView.setBackgroundColor(Color.WHITE);
    // Set background color of the snackbar
    TextView textView = sbView.findViewById(com.google.android.material.R.id.snackbar_text);
    textView.setTextColor(Color.BLACK);
    snackbar.show();
}
 
Example 12
Source File: MainActivity.java    From android-popular-movies-app with Apache License 2.0 5 votes vote down vote up
/**
 * When offline, show a snackbar message
 */
private void showSnackbarOffline() {
    Snackbar snackbar = Snackbar.make(
            mMainBinding.frameMain, R.string.snackbar_offline, Snackbar.LENGTH_LONG);
    // Set background color of the snackbar
    View sbView = snackbar.getView();
    sbView.setBackgroundColor(Color.WHITE);
    // Set background color of the snackbar
    TextView textView = sbView.findViewById(com.google.android.material.R.id.snackbar_text);
    textView.setTextColor(Color.BLACK);
    snackbar.show();
}
 
Example 13
Source File: DetailActivity.java    From android-popular-movies-app with Apache License 2.0 5 votes vote down vote up
/**
 * Show a snackbar message when a movie removed from MovieDatbase
 */
private void showSnackbarRemoved() {
    Snackbar snackbar = Snackbar.make(
            mDetailBinding.coordinator, R.string.snackbar_removed, Snackbar.LENGTH_SHORT);
    // Set background color of the snackbar
    View sbView = snackbar.getView();
    sbView.setBackgroundColor(Color.WHITE);
    // Set background color of the snackbar
    TextView textView = sbView.findViewById(com.google.android.material.R.id.snackbar_text);
    textView.setTextColor(Color.BLACK);
    snackbar.show();
}
 
Example 14
Source File: DetailActivity.java    From android-popular-movies-app with Apache License 2.0 5 votes vote down vote up
/**
 * Show a snackbar message when a movie added to MovieDatabase
 *
 * Reference: @see "https://stackoverflow.com/questions/34020891/how-to-change-background-color-of-the-snackbar"
 */
private void showSnackbarAdded() {
    Snackbar snackbar = Snackbar.make(
            mDetailBinding.coordinator, R.string.snackbar_added, Snackbar.LENGTH_SHORT);
    // Set background color of the snackbar
    View sbView = snackbar.getView();
    sbView.setBackgroundColor(Color.WHITE);
    // Set text color of the snackbar
    TextView textView = sbView.findViewById(com.google.android.material.R.id.snackbar_text);
    textView.setTextColor(Color.BLACK);
    snackbar.show();
}
 
Example 15
Source File: BaseAppCompatActivity.java    From zap-android with MIT License 5 votes vote down vote up
protected void showError(String message, int duration) {
    Snackbar msg = Snackbar.make(findViewById(android.R.id.content), message, Snackbar.LENGTH_LONG);
    View sbView = msg.getView();
    sbView.setBackgroundColor(ContextCompat.getColor(this, R.color.superRed));
    msg.setDuration(duration);
    msg.show();
}
 
Example 16
Source File: WalletFragment.java    From zap-android with MIT License 5 votes vote down vote up
private void showError(String message, int duration) {
    Snackbar msg = Snackbar.make(getActivity().findViewById(R.id.mainContent), message, Snackbar.LENGTH_LONG);
    View sbView = msg.getView();
    sbView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.superRed));
    msg.setDuration(duration);
    msg.show();
}
 
Example 17
Source File: NotificationHelper.java    From Mysplash with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void showSnackbar(@NonNull MysplashActivity activity, String content) {
    View container = activity.provideSnackbarContainer();
    if (container != null) {
        Snackbar snackbar = Snackbar.make(container, content, Snackbar.LENGTH_SHORT);

        Snackbar.SnackbarLayout snackbarLayout = (Snackbar.SnackbarLayout) snackbar.getView();
        snackbarLayout.setBackgroundColor(ThemeManager.getRootColor(activity));

        TextView contentTxt = snackbarLayout.findViewById(R.id.snackbar_text);
        contentTxt.setTextColor(ThemeManager.getContentColor(activity));

        snackbar.show();
    }
}
 
Example 18
Source File: OpenChannelBSDFragment.java    From zap-android with MIT License 4 votes vote down vote up
private void showError(String message, int duration) {
    Snackbar msg = Snackbar.make(getView().findViewById(R.id.coordinator), message, duration);
    View sbView = msg.getView();
    sbView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.superRed));
    msg.show();
}
 
Example 19
Source File: CustomSnackbar.java    From evercam-android with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void showLong(Activity activity, int messageId) {
    Snackbar snackbar = Snackbar.make(activity.findViewById(android.R.id.content), messageId, Snackbar.LENGTH_LONG);
    View snackbarView = snackbar.getView();
    snackbarView.setBackgroundColor(activity.getResources().getColor(R.color.dark_gray_background));
    snackbar.show();
}
 
Example 20
Source File: SnackbarUtil.java    From weather with Apache License 2.0 4 votes vote down vote up
/**
 * Return the view of snackbar.
 *
 * @return the view of snackbar
 */
public static View getView() {
  Snackbar snackbar = sReference.get();
  if (snackbar == null) return null;
  return snackbar.getView();
}