Java Code Examples for android.support.design.widget.Snackbar#setActionTextColor()

The following examples show how to use android.support.design.widget.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: MainActivity.java    From GNSS_Compare with Apache License 2.0 6 votes vote down vote up
public static void makeDismissableNotification(String note, int length){

        final Snackbar snackbar = Snackbar
                .make(mainView, note, length);

        snackbar.setAction("Dismiss", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                snackbar.dismiss();
            }
        });

        snackbar.setActionTextColor(dismissableNotificationTextColor);

        snackbar.show();
    }
 
Example 2
Source File: AgentWebUtils.java    From AgentWeb with Apache License 2.0 6 votes vote down vote up
static void show(View parent,
                 CharSequence text,
                 int duration,
                 @ColorInt int textColor,
                 @ColorInt int bgColor,
                 CharSequence actionText,
                 @ColorInt int actionTextColor,
                 View.OnClickListener listener) {
	SpannableString spannableString = new SpannableString(text);
	ForegroundColorSpan colorSpan = new ForegroundColorSpan(textColor);
	spannableString.setSpan(colorSpan, 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
	snackbarWeakReference = new WeakReference<>(Snackbar.make(parent, spannableString, duration));
	Snackbar snackbar = snackbarWeakReference.get();
	View view = snackbar.getView();
	view.setBackgroundColor(bgColor);
	if (actionText != null && actionText.length() > 0 && listener != null) {
		snackbar.setActionTextColor(actionTextColor);
		snackbar.setAction(actionText, listener);
	}
	snackbar.show();
}
 
Example 3
Source File: SnackbarUtils.java    From Android-UtilCode with Apache License 2.0 6 votes vote down vote up
/**
 * 设置snackbar文字和背景颜色
 *
 * @param parent          父视图(CoordinatorLayout或者DecorView)
 * @param text            文本
 * @param duration        显示时长
 * @param textColor       文本颜色
 * @param bgColor         背景色
 * @param actionText      事件文本
 * @param actionTextColor 事件文本颜色
 * @param listener        监听器
 */
private static void show(View parent,
                         CharSequence text,
                         int duration,
                         @ColorInt int textColor,
                         @ColorInt int bgColor,
                         CharSequence actionText,
                         @ColorInt int actionTextColor,
                         View.OnClickListener listener) {
    SpannableString spannableString = new SpannableString(text);
    ForegroundColorSpan colorSpan = new ForegroundColorSpan(textColor);
    spannableString.setSpan(colorSpan, 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    snackbarWeakReference = new WeakReference<>(Snackbar.make(parent, spannableString, duration));
    Snackbar snackbar = snackbarWeakReference.get();
    View view = snackbar.getView();
    view.setBackgroundColor(bgColor);
    if (actionText != null && actionText.length() > 0 && listener != null) {
        snackbar.setActionTextColor(actionTextColor);
        snackbar.setAction(actionText, listener);
    }
    snackbar.show();
}
 
Example 4
Source File: ContactViewFragment.java    From weMessage with GNU Affero General Public License v3.0 6 votes vote down vote up
private void showErroredSnackBar(String message){
    if (getView() != null) {
        final Snackbar snackbar = Snackbar.make(getView(), message, ERROR_SNACKBAR_DURATION * 1000);

        snackbar.setAction(getString(R.string.dismiss_button), new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                snackbar.dismiss();
            }
        });
        snackbar.setActionTextColor(getResources().getColor(R.color.brightRedText));

        View snackbarView = snackbar.getView();
        TextView textView = snackbarView.findViewById(android.support.design.R.id.snackbar_text);
        textView.setMaxLines(5);

        snackbar.show();
    }
}
 
Example 5
Source File: RecordsActivity.java    From Android-Bluetooth-Fingerprint with Apache License 2.0 6 votes vote down vote up
private void showSnackBar(final int id, String msg) {
    CoordinatorLayout coordinatorLayout = (CoordinatorLayout)
            findViewById(R.id.records_coordinator_layout);

    Snackbar snackbar = Snackbar
            .make(coordinatorLayout, msg, Snackbar.LENGTH_LONG);

    // Changing message text color
    snackbar.setActionTextColor(Color.RED);

    // Changing action button text color
    View sbView = snackbar.getView();
    TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
    textView.setTextColor(Color.YELLOW);
    snackbar.show();

}
 
Example 6
Source File: AttachmentPopupFragment.java    From weMessage with GNU Affero General Public License v3.0 6 votes vote down vote up
private void showErroredSnackBar(String message){
    if (getParentFragment().getView() != null) {
        final Snackbar snackbar = Snackbar.make(getParentFragment().getView(), message, ERROR_SNACKBAR_DURATION * 1000);

        snackbar.setAction(getString(R.string.dismiss_button), new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                snackbar.dismiss();
            }
        });
        snackbar.setActionTextColor(getResources().getColor(R.color.brightRedText));

        View snackbarView = snackbar.getView();
        TextView textView = snackbarView.findViewById(android.support.design.R.id.snackbar_text);
        textView.setMaxLines(5);

        snackbar.show();
    }
}
 
Example 7
Source File: HistoryActivity.java    From Android-Bluetooth-Fingerprint with Apache License 2.0 6 votes vote down vote up
private void showSnackBar(final int id, String msg) {
    CoordinatorLayout coordinatorLayout = (CoordinatorLayout)
            findViewById(R.id.history_coordinator_layout);

    Snackbar snackbar = Snackbar
            .make(coordinatorLayout, msg, Snackbar.LENGTH_LONG);

    // Changing message text color
    snackbar.setActionTextColor(Color.RED);

    // Changing action button text color
    View sbView = snackbar.getView();
    TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
    textView.setTextColor(Color.YELLOW);
    snackbar.show();

}
 
Example 8
Source File: SettingsActivity.java    From weMessage with GNU Affero General Public License v3.0 6 votes vote down vote up
private void showErroredSnackbar(String message, int duration){
    if (!isFinishing() && !isDestroyed()) {
        final Snackbar snackbar = Snackbar.make(findViewById(R.id.settingsLayout), message, duration * 1000);

        snackbar.setAction(getString(R.string.dismiss_button), new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                snackbar.dismiss();
            }
        });
        snackbar.setActionTextColor(getResources().getColor(R.color.brightRedText));

        View snackbarView = snackbar.getView();
        TextView textView = snackbarView.findViewById(android.support.design.R.id.snackbar_text);
        textView.setMaxLines(5);

        snackbar.show();
    }
}
 
Example 9
Source File: ContactListActivity.java    From weMessage with GNU Affero General Public License v3.0 6 votes vote down vote up
private void showErroredSnackbar(String message, int duration){
    if (!isFinishing() && !isDestroyed()) {
        final Snackbar snackbar = Snackbar.make(findViewById(R.id.contactSelectLayout), message, duration * 1000);

        snackbar.setAction(getString(R.string.dismiss_button), new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                snackbar.dismiss();
            }
        });
        snackbar.setActionTextColor(getResources().getColor(R.color.brightRedText));

        View snackbarView = snackbar.getView();
        TextView textView = snackbarView.findViewById(android.support.design.R.id.snackbar_text);
        textView.setMaxLines(5);

        snackbar.show();
    }
}
 
Example 10
Source File: PermissMeUtils.java    From PermissMe with Apache License 2.0 6 votes vote down vote up
/**
 * Displays a SnackBar message.
 *
 * @param view
 * 		the view to find a parent from.
 * @param msg
 * 		the message to display.
 * @param backgroundColor
 * 		the background color.
 * @param ctaString
 * 		the call to action string
 * @param ctaClickListener
 * 		the call to action click listener.
 */
public static void showSnackBar(final View view,
                                final String msg,
                                final int backgroundColor,
                                final String ctaString,
                                final View.OnClickListener ctaClickListener) {
	final Snackbar snack = Snackbar.make(view, msg,
			ctaString != null ? Snackbar.LENGTH_LONG : Snackbar.LENGTH_SHORT);

	final ViewGroup group = (ViewGroup) snack.getView();
	group.setBackgroundColor(backgroundColor);

	final int textColor =
			view.getContext().getResources().getColor(PermissMeConfig.getInstance().getTextColorRes());
	if (ctaString != null && ctaClickListener != null) {
		snack.setActionTextColor(textColor);
		snack.setAction(ctaString, ctaClickListener);
	}

	snack.show();
}
 
Example 11
Source File: TabbedMainActivity.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
private TextView showWarningBanner(final String message, final String hideCfgName) {
    if (hideCfgName != null && mService.cfg().getBoolean(hideCfgName, false))
        return null;

    final Snackbar snackbar = Snackbar
            .make(findViewById(R.id.main_content), message, Snackbar.LENGTH_INDEFINITE);

    if (hideCfgName != null) {
        snackbar.setActionTextColor(Color.RED);
        snackbar.setAction(getString(R.string.set2FA), new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                final Intent intent = new Intent(TabbedMainActivity.this, SettingsActivity.class);
                intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, TwoFactorPreferenceFragment.class.getName());
                startActivityForResult(intent, REQUEST_SETTINGS);
            }
        });
    }

    final View snackbarView = snackbar.getView();
    snackbarView.setBackgroundColor(Color.DKGRAY);
    final TextView textView = UI.find(snackbarView, android.support.design.R.id.snackbar_text);
    textView.setTextColor(Color.WHITE);
    snackbar.show();
    return textView;
}
 
Example 12
Source File: ChatListFragment.java    From weMessage with GNU Affero General Public License v3.0 6 votes vote down vote up
private void showErroredSnackbar(String message){
    if (getView() != null) {
        final Snackbar snackbar = Snackbar.make(getView(), message, ERROR_SNACKBAR_DURATION * 1000);

        snackbar.setAction(getString(R.string.dismiss_button), new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                snackbar.dismiss();
            }
        });
        snackbar.setActionTextColor(getResources().getColor(R.color.brightRedText));

        View snackbarView = snackbar.getView();
        TextView textView = snackbarView.findViewById(android.support.design.R.id.snackbar_text);
        textView.setMaxLines(5);

        snackbar.show();
    }
}
 
Example 13
Source File: SuntimesWarning.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
@SuppressLint("ResourceType")
private void themeWarning(@NonNull Context context, @NonNull Snackbar snackbarWarning)
{
    int[] colorAttrs = { R.attr.snackbar_textColor, R.attr.snackbar_accentColor, R.attr.snackbar_backgroundColor };
    TypedArray a = context.obtainStyledAttributes(colorAttrs);
    int textColor = ContextCompat.getColor(context, a.getResourceId(0, android.R.color.primary_text_dark));
    int accentColor = ContextCompat.getColor(context, a.getResourceId(1, R.color.text_accent_dark));
    int backgroundColor = ContextCompat.getColor(context, a.getResourceId(2, R.color.card_bg_dark));
    a.recycle();

    View snackbarView = snackbarWarning.getView();
    snackbarView.setBackgroundColor(backgroundColor);
    snackbarWarning.setActionTextColor(accentColor);

    TextView snackbarText = (TextView)snackbarView.findViewById(android.support.design.R.id.snackbar_text);
    if (snackbarText != null) {
        snackbarText.setTextColor(textColor);
        snackbarText.setMaxLines(5);
    }
}
 
Example 14
Source File: DisplayUtils.java    From weMessage with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void showPositiveSnackbar(Context context, View view, int duration, String message){
    final Snackbar snackbar = Snackbar.make(view, message, duration * 1000);

    snackbar.setAction(context.getString(R.string.ok_button), new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            snackbar.dismiss();
        }
    });
    snackbar.setActionTextColor(context.getResources().getColor(R.color.colorHeader));

    View snackbarView = snackbar.getView();
    TextView textView = snackbarView.findViewById(android.support.design.R.id.snackbar_text);
    textView.setMaxLines(5);

    snackbar.show();
}
 
Example 15
Source File: MainFragment.java    From android-auto-call-recorder with MIT License 6 votes vote down vote up
private void showSnackbar() {
    Snackbar snackbar = Snackbar
            .make(mCoordinatorLayout, "test test", Snackbar.LENGTH_LONG)
            .setAction("UNDO", new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Snackbar snackbar1 = Snackbar.make(mCoordinatorLayout, "Message is restored!", Snackbar.LENGTH_SHORT);
                    snackbar1.show();
                }
            });
    // Changing message text color
    snackbar.setActionTextColor(Color.RED);

    // Changing action button text color
    View sbView = snackbar.getView();
    TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
    textView.setTextColor(Color.YELLOW);
    snackbar.show();
}
 
Example 16
Source File: MainActivity.java    From journaldev with MIT License 5 votes vote down vote up
private void enableSwipeToDeleteAndUndo() {
    SwipeToDeleteCallback swipeToDeleteCallback = new SwipeToDeleteCallback(this) {
        @Override
        public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int i) {


            final int position = viewHolder.getAdapterPosition();
            final String item = mAdapter.getData().get(position);

            mAdapter.removeItem(position);


            Snackbar snackbar = Snackbar
                    .make(coordinatorLayout, "Item was removed from the list.", Snackbar.LENGTH_LONG);
            snackbar.setAction("UNDO", new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    mAdapter.restoreItem(item, position);
                    recyclerView.scrollToPosition(position);
                }
            });

            snackbar.setActionTextColor(Color.YELLOW);
            snackbar.show();

        }
    };

    ItemTouchHelper itemTouchhelper = new ItemTouchHelper(swipeToDeleteCallback);
    itemTouchhelper.attachToRecyclerView(recyclerView);
}
 
Example 17
Source File: DashBoardActivity.java    From Android-Bluetooth-Fingerprint with Apache License 2.0 5 votes vote down vote up
private void showSnackBar(String msg) {
    CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.dash_board_coordinator_layout);
    Snackbar snackbar = Snackbar
            .make(coordinatorLayout, msg, Snackbar.LENGTH_LONG);
   /* if(id == 0){
        snackbar.setAction("RETRY", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (cd.isConnectingToInternet())
                    submitLogin();
                else
                    showSnackBar(0, getString(R.string.err_no_internet));
            }
        });
    }*/


    // Changing message text color
    snackbar.setActionTextColor(Color.RED);

    // Changing action button text color
    View sbView = snackbar.getView();
    TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
    textView.setTextColor(Color.WHITE);
    snackbar.show();

}
 
Example 18
Source File: EnrollActivity.java    From Android-Bluetooth-Fingerprint with Apache License 2.0 5 votes vote down vote up
private void showSnackBar(String msg) {
    CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.enroll_coordinator_layout);
    Snackbar snackbar = Snackbar
            .make(coordinatorLayout, msg, Snackbar.LENGTH_LONG);

    // Changing message text color
    snackbar.setActionTextColor(Color.RED);

    // Changing action button text color
    View sbView = snackbar.getView();
    TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
    textView.setTextColor(Color.WHITE);
    snackbar.show();

}
 
Example 19
Source File: CaptureActivity.java    From Android-Bluetooth-Fingerprint with Apache License 2.0 5 votes vote down vote up
private void showSnackBar(String msg) {
    CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.sign_on_coordinator_layout);
    Snackbar snackbar = Snackbar
            .make(coordinatorLayout, msg, Snackbar.LENGTH_LONG);

    // Changing message text color
    snackbar.setActionTextColor(Color.RED);

    // Changing action button text color
    View sbView = snackbar.getView();
    TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
    textView.setTextColor(Color.WHITE);
    snackbar.show();

}
 
Example 20
Source File: SnackbarUtils.java    From AndroidUtilCode with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}