Search in sources :

Example 1 with SnackbarContentLayout

use of android.support.design.internal.SnackbarContentLayout in project material-components-android by material-components.

the class Snackbar method setText.

/**
   * Update the text in this {@link Snackbar}.
   *
   * @param message The new text for this {@link BaseTransientBottomBar}.
   */
@NonNull
public Snackbar setText(@NonNull CharSequence message) {
    final SnackbarContentLayout contentLayout = (SnackbarContentLayout) mView.getChildAt(0);
    final TextView tv = contentLayout.getMessageView();
    tv.setText(message);
    return this;
}
Also used : SnackbarContentLayout(android.support.design.internal.SnackbarContentLayout) TextView(android.widget.TextView) NonNull(android.support.annotation.NonNull)

Example 2 with SnackbarContentLayout

use of android.support.design.internal.SnackbarContentLayout in project material-components-android by material-components.

the class Snackbar method make.

/**
   * Make a Snackbar to display a message
   *
   * <p>Snackbar will try and find a parent view to hold Snackbar's view from the value given to
   * {@code view}. Snackbar will walk up the view tree trying to find a suitable parent, which is
   * defined as a {@link CoordinatorLayout} or the window decor's content view, whichever comes
   * first.
   *
   * <p>Having a {@link CoordinatorLayout} in your view hierarchy allows Snackbar to enable certain
   * features, such as swipe-to-dismiss and automatically moving of widgets like {@link
   * FloatingActionButton}.
   *
   * @param view The view to find a parent from.
   * @param text The text to show. Can be formatted text.
   * @param duration How long to display the message. Either {@link #LENGTH_SHORT} or {@link
   *     #LENGTH_LONG}
   */
@NonNull
public static Snackbar make(@NonNull View view, @NonNull CharSequence text, @Duration int duration) {
    final ViewGroup parent = findSuitableParent(view);
    if (parent == null) {
        throw new IllegalArgumentException("No suitable parent found from the given view. Please provide a valid view.");
    }
    final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    final SnackbarContentLayout content = (SnackbarContentLayout) inflater.inflate(R.layout.design_layout_snackbar_include, parent, false);
    final Snackbar snackbar = new Snackbar(parent, content, content);
    snackbar.setText(text);
    snackbar.setDuration(duration);
    return snackbar;
}
Also used : SnackbarContentLayout(android.support.design.internal.SnackbarContentLayout) ViewGroup(android.view.ViewGroup) LayoutInflater(android.view.LayoutInflater) NonNull(android.support.annotation.NonNull)

Example 3 with SnackbarContentLayout

use of android.support.design.internal.SnackbarContentLayout in project material-components-android by material-components.

the class Snackbar method setActionTextColor.

/**
   * Sets the text color of the action specified in {@link #setAction(CharSequence,
   * View.OnClickListener)}.
   */
@NonNull
public Snackbar setActionTextColor(@ColorInt int color) {
    final SnackbarContentLayout contentLayout = (SnackbarContentLayout) mView.getChildAt(0);
    final TextView tv = contentLayout.getActionView();
    tv.setTextColor(color);
    return this;
}
Also used : SnackbarContentLayout(android.support.design.internal.SnackbarContentLayout) TextView(android.widget.TextView) NonNull(android.support.annotation.NonNull)

Example 4 with SnackbarContentLayout

use of android.support.design.internal.SnackbarContentLayout in project material-components-android by material-components.

the class Snackbar method setActionTextColor.

/**
   * Sets the text color of the action specified in {@link #setAction(CharSequence,
   * View.OnClickListener)}.
   */
@NonNull
public Snackbar setActionTextColor(ColorStateList colors) {
    final SnackbarContentLayout contentLayout = (SnackbarContentLayout) mView.getChildAt(0);
    final TextView tv = contentLayout.getActionView();
    tv.setTextColor(colors);
    return this;
}
Also used : SnackbarContentLayout(android.support.design.internal.SnackbarContentLayout) TextView(android.widget.TextView) NonNull(android.support.annotation.NonNull)

Example 5 with SnackbarContentLayout

use of android.support.design.internal.SnackbarContentLayout in project material-components-android by material-components.

the class Snackbar method setAction.

/**
   * Set the action to be displayed in this {@link BaseTransientBottomBar}.
   *
   * @param text Text to display for the action
   * @param listener callback to be invoked when the action is clicked
   */
@NonNull
public Snackbar setAction(CharSequence text, final View.OnClickListener listener) {
    final SnackbarContentLayout contentLayout = (SnackbarContentLayout) mView.getChildAt(0);
    final TextView tv = contentLayout.getActionView();
    if (TextUtils.isEmpty(text) || listener == null) {
        tv.setVisibility(View.GONE);
        tv.setOnClickListener(null);
    } else {
        tv.setVisibility(View.VISIBLE);
        tv.setText(text);
        tv.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                listener.onClick(view);
                // Now dismiss the Snackbar
                dispatchDismiss(BaseCallback.DISMISS_EVENT_ACTION);
            }
        });
    }
    return this;
}
Also used : SnackbarContentLayout(android.support.design.internal.SnackbarContentLayout) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) NonNull(android.support.annotation.NonNull)

Aggregations

NonNull (android.support.annotation.NonNull)5 SnackbarContentLayout (android.support.design.internal.SnackbarContentLayout)5 TextView (android.widget.TextView)4 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1