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

The following examples show how to use com.google.android.material.snackbar.Snackbar#setActionTextColor() . 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: 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 2
Source File: BaseActivity.java    From Instagram-Profile-Downloader with MIT License 6 votes vote down vote up
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: DetailsActivity.java    From tracker-control-android with GNU General Public License v3.0 6 votes vote down vote up
protected void onPostExecute(final Boolean success) {
    if (this.dialog.isShowing()) {
        this.dialog.dismiss();
    }

    if (!success) {
        Toast.makeText(DetailsActivity.this, R.string.export_failed, Toast.LENGTH_SHORT).show();
        return;
    }

    // Export successful, ask user to further share file!
    View v = findViewById(R.id.view_pager);
    Snackbar s = Snackbar.make(v, R.string.exported, Snackbar.LENGTH_LONG);
    s.setAction(R.string.share_csv, v1 -> shareExport());
    s.setActionTextColor(getResources().getColor(R.color.colorPrimary));
    s.show();
}
 
Example 4
Source File: DynamicHintUtils.java    From dynamic-support with Apache License 2.0 6 votes vote down vote up
/**
 * Make a themed snack bar with text and action.
 *
 * @param view The view to show the snack bar.
 * @param text The text to show. Can be formatted text.
 * @param backgroundColor The snack bar background color.
 * @param tintColor The snack bar tint color based on the background. It will automatically
 *                  check for the contrast to provide bes visibility.
 * @param duration The duration of the snack bar.
 *                 <p>Can be {@link Snackbar#LENGTH_SHORT}, {@link Snackbar#LENGTH_LONG}
 *                 or {@link Snackbar#LENGTH_INDEFINITE}.
 *
 * @return The snack bar with the supplied parameters.
 *         <p>Use {@link Snackbar#show()} to display the snack bar.
 */
public static @NonNull Snackbar getSnackBar(@NonNull View view,
        @NonNull CharSequence text, @ColorInt int backgroundColor,
        @ColorInt int tintColor, @Snackbar.Duration int duration) {
    if (DynamicTheme.getInstance().get().isBackgroundAware()) {
        backgroundColor = DynamicColorUtils.getContrastColor(backgroundColor,
                DynamicTheme.getInstance().get().getBackgroundColor());
        tintColor = DynamicColorUtils.getContrastColor(tintColor, backgroundColor);
    }

    Snackbar snackbar = Snackbar.make(view, text, duration);
    DynamicDrawableUtils.setBackground(snackbar.getView(),
            DynamicDrawableUtils.getCornerDrawable(DynamicTheme.getInstance()
                    .get().getCornerSizeDp(), backgroundColor));
    ((TextView) snackbar.getView().findViewById(
            R.id.snackbar_text)).setTextColor(tintColor);
    ((TextView) snackbar.getView().findViewById(
            R.id.snackbar_text)).setMaxLines(Integer.MAX_VALUE);
    snackbar.setActionTextColor(tintColor);

    return snackbar;
}
 
Example 5
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 6
Source File: SnackbarUtil.java    From weather with Apache License 2.0 5 votes vote down vote up
/**
 * Show the snackbar.
 */
public Snackbar show() {
  final View view = this.view;
  if (view == null) return null;
  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 View snackbarView = snackbar.getView();
  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 7
Source File: PlayingQueueAdapter.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
public static void initializeSnackBar(final PlayingQueueAdapter adapter,final int position,
                                      final AppCompatActivity activity,
                                      final boolean isPlayingSongToRemove) {

    CharSequence snackBarTitle = activity.getString(R.string.snack_bar_title_removed_song);

    Snackbar snackbar = Snackbar.make(activity.findViewById(R.id.content_container),
            snackBarTitle,
            Snackbar.LENGTH_LONG);

    TextView songTitle = snackbar.getView().findViewById(R.id.snackbar_text);

    songTitle.setSingleLine();
    songTitle.setEllipsize(TextUtils.TruncateAt.END);
    songTitle.setText(adapter.dataSet.get(position).title + " " + snackBarTitle);

    snackbar.setAction(R.string.snack_bar_action_undo, v -> {
        MusicPlayerRemote.addSong(position,adapter.getSongToRemove());
        //If playing and currently playing song is removed, then added back, then play it at
        //current song progress
        if (isPlayingSongToRemove) {
            MusicPlayerRemote.playSongAt(position);
        }
    });
    snackbar.setActionTextColor(getBackgroundColor(activity));
    snackbar.show();


    //Fixes Snackbar not showing when it replaces another Snackbar
    //See: https://stackoverflow.com/questions/43680655/snackbar-sometimes-doesnt-show-up-when-it-replaces-another-one
    currentlyShownSnackbar = snackbar;

}
 
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: DownloadBroadcastReceiver.java    From focus-android with Mozilla Public License 2.0 5 votes vote down vote up
private void showSnackbarForFilename(final Intent openFileIntent, final Context context, String fileName) {
    final Snackbar snackbar = Snackbar
            .make(browserContainer, String.format(context.getString(R.string.download_snackbar_finished), fileName), Snackbar.LENGTH_LONG);
    if (IntentUtils.INSTANCE.activitiesFoundForIntent(context, openFileIntent)) {
        snackbar.setAction(context.getString(R.string.download_snackbar_open), new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                context.startActivity(openFileIntent);
            }
        });
        snackbar.setActionTextColor(ContextCompat.getColor(context, R.color.snackbarActionText));
    }
    snackbar.show();
}
 
Example 10
Source File: AccessibilityUtils.java    From science-journal with Apache License 2.0 5 votes vote down vote up
public static Snackbar makeSnackbar(View view, String message, int length) {
  Context context = view.getContext();
  Snackbar bar = Snackbar.make(view, message, length);
  bar.getView().setContentDescription(message);
  bar.setDuration(getLongerToastDurationIfAccessibilityEnabled(context, bar));
  bar.setActionTextColor(context.getResources().getColor(R.color.snackbar_action_color));
  return bar;
}
 
Example 11
Source File: AccessibilityUtils.java    From science-journal with Apache License 2.0 5 votes vote down vote up
public static Snackbar makeSnackbar(
    View view, String message, int length, String action, OnClickListener onClickAction) {
  Context context = view.getContext();
  Snackbar bar = Snackbar.make(view, message, length);
  bar.getView().setContentDescription(message);
  bar.setDuration(getLongerToastDurationIfAccessibilityEnabled(context, bar));
  bar.setActionTextColor(context.getResources().getColor(R.color.snackbar_action_color));
  bar.setAction(action, onClickAction);
  return bar;
}
 
Example 12
Source File: BrandedSnackbar.java    From nextcloud-notes with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
public static Snackbar make(@NonNull View view, @NonNull CharSequence text, @BaseTransientBottomBar.Duration int duration) {
    final Snackbar snackbar = Snackbar.make(view, text, duration);
    if (BrandingUtil.isBrandingEnabled(view.getContext())) {
        int color = BrandingUtil.readBrandMainColor(view.getContext());
        snackbar.setActionTextColor(ColorUtil.isColorDark(color) ? Color.WHITE : color);
    }
    return snackbar;
}
 
Example 13
Source File: AppSnackbar.java    From hash-checker with Apache License 2.0 4 votes vote down vote up
public void show() {
    Snackbar snackbar = Snackbar.make(
            parent,
            message,
            Snackbar.LENGTH_SHORT
    );
    if (action != null) {
        snackbar.setAction(actionText, action);
    } else {
        final Snackbar closableSnackbar = snackbar;
        snackbar.setAction(
                context.getResources().getString(R.string.common_ok),
                v -> closableSnackbar.dismiss()
        );
        ((ViewGroup) snackbar.getView()).getChildAt(0)
                .setPadding(
                        COMMON_SNACKBAR_MARGIN,
                        COMMON_SNACKBAR_MARGIN,
                        COMMON_SNACKBAR_MARGIN,
                        COMMON_SNACKBAR_MARGIN
                );
    }
    snackbar.setActionTextColor(textColor);
    snackbar.getView().setBackground(
            ContextCompat.getDrawable(
                    context,
                    R.drawable.bg_snackbar
            )
    );

    TextView snackbarText = snackbar.getView().findViewById(
            R.id.snackbar_text
    );
    snackbarText.setTextColor(
            UIUtils.getCommonTextColor(
                    context
            )
    );
    snackbar.show();

    if (SettingsHelper.getVibrateAccess(context)) {
        vibrator.vibrate();
    }
}