Java Code Examples for android.support.design.widget.Snackbar#getView()
The following examples show how to use
android.support.design.widget.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: SnackBar_Activity.java From Study_Android_Demo with Apache License 2.0 | 6 votes |
public void showSnackBar(View view){ //snackbar最好配合CoordinatorLayout使用 (SnackBar可以直接右滑出去) //也可以避免控件的遮挡 Snackbar snackbar = Snackbar.make(contain, "Hi! I'am SnackBar", Snackbar.LENGTH_SHORT) .setAction("Click me", new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(SnackBar_Activity.this, "ByeBye", Toast.LENGTH_SHORT).show(); } }) // 设定提示action的内容(上面Hi! I'am SnackBar不会显示) // .setText("hi realmo") //设置Action字体颜色 .setActionTextColor(Color.parseColor("#8800ff00")); //snackbar文字的颜色 View snackView = snackbar.getView(); TextView tvSnackView = (TextView) snackView.findViewById(android.support.design.R.id.snackbar_text); tvSnackView.setTextColor(Color.BLUE); //设置背景颜色 snackView.setBackgroundColor(Color.parseColor("#66554433")); //显示snackbar snackbar.show(); }
Example 2
Source File: DisplayUtils.java From weMessage with GNU Affero General Public License v3.0 | 6 votes |
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 3
Source File: TabbedMainActivity.java From GreenBits with GNU General Public License v3.0 | 6 votes |
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 4
Source File: ChatListFragment.java From weMessage with GNU Affero General Public License v3.0 | 6 votes |
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: ForgotPasswordActivity.java From faveo-helpdesk-android-app with Open Software License 3.0 | 6 votes |
private void showSnackIfNoInternet(boolean isConnected) { if (!isConnected) { final Snackbar snackbar = Snackbar .make(findViewById(android.R.id.content), "Sorry! Not connected to internet", Snackbar.LENGTH_INDEFINITE); View sbView = snackbar.getView(); TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text); textView.setTextColor(Color.RED); snackbar.setAction("X", new View.OnClickListener() { @Override public void onClick(View v) { snackbar.dismiss(); } }); snackbar.show(); } }
Example 6
Source File: CreateChatFragment.java From weMessage with GNU Affero General Public License v3.0 | 6 votes |
private void showErroredSnackbar(String message, int duration){ if (getView() != null) { final Snackbar snackbar = Snackbar.make(getView(), 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 7
Source File: MainActivity.java From Android-nRF-BLE-Joiner with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void showError(final String error, boolean setAction){ final Snackbar snackbar = Snackbar .make(mRelativeLayout, error, Snackbar.LENGTH_LONG); final View snackbarView = snackbar.getView(); snackbarView.setBackgroundColor(Color.DKGRAY); final TextView textView = (TextView) snackbarView.findViewById(android.support.design.R.id.snackbar_text); textView.setTextColor(Color.WHITE); if(setAction) snackbar.setActionTextColor(ContextCompat.getColor(this, R.color.colorPrimary)).setAction(R.string.action_settings, new View.OnClickListener() { @Override public void onClick(final View v) { final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(intent); } }); snackbar.show(); }
Example 8
Source File: SettingsActivity.java From weMessage with GNU Affero General Public License v3.0 | 6 votes |
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: MainActivity.java From faveo-helpdesk-android-app with Open Software License 3.0 | 6 votes |
/** * Display the snackbar if network connection is not there. * * @param isConnected is a boolean value of network connection. */ private void showSnackIfNoInternet(boolean isConnected) { if (!isConnected) { final Snackbar snackbar = Snackbar .make(findViewById(android.R.id.content), R.string.sry_not_connected_to_internet, Snackbar.LENGTH_INDEFINITE); View sbView = snackbar.getView(); TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text); textView.setTextColor(Color.RED); snackbar.setAction("X", new View.OnClickListener() { @Override public void onClick(View v) { snackbar.dismiss(); } }); snackbar.show(); } }
Example 10
Source File: AttachmentPopupFragment.java From weMessage with GNU Affero General Public License v3.0 | 6 votes |
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 11
Source File: SnackbarUtil.java From CoordinatorLayoutExample with Apache License 2.0 | 5 votes |
/** * 设置Snackbar文字和背景颜色 * @param snackbar * @param messageColor * @param backgroundColor */ public static void setSnackbarColor(Snackbar snackbar, int messageColor, int backgroundColor) { View view = snackbar.getView(); if(view!=null){ view.setBackgroundColor(backgroundColor); ((TextView) view.findViewById(R.id.snackbar_text)).setTextColor(messageColor); } }
Example 12
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 13
Source File: PopulateShadowboxInfo.java From Slide with GNU General Public License v3.0 | 5 votes |
@Override protected void onPostExecute(Void aVoid) { Snackbar s = Snackbar.make(contextView, R.string.msg_report_sent, Snackbar.LENGTH_SHORT); View view = s.getView(); TextView tv = view.findViewById( android.support.design.R.id.snackbar_text); tv.setTextColor(Color.WHITE); s.show(); }
Example 14
Source File: SubmissionComments.java From Slide with GNU General Public License v3.0 | 5 votes |
public void loadMoreReplyTop(CommentAdapter adapter, String context) { this.adapter = adapter; adapter.currentSelectedItem = context; mLoadData = new LoadData(true); mLoadData.execute(fullName); if (context == null || context.isEmpty()) { Snackbar s = Snackbar.make(page.rv, "Comment submitted", Snackbar.LENGTH_SHORT); View view = s.getView(); TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text); tv.setTextColor(Color.WHITE); s.show(); } }
Example 15
Source File: FormActivity.java From android-mvp with Apache License 2.0 | 5 votes |
protected void showMessage(View container, String message) { Snackbar snackbar = Snackbar .make(container,message, Snackbar.LENGTH_LONG); snackbar.setActionTextColor(Color.RED); View sbView = snackbar.getView(); TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text); textView.setTextColor(Color.WHITE); snackbar.show(); }
Example 16
Source File: EnrollActivity.java From Android-Bluetooth-Fingerprint with Apache License 2.0 | 5 votes |
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 17
Source File: MainActivity.java From OneTapVideoDownload with GNU General Public License v3.0 | 5 votes |
private void displaySnackbar(String text, String actionName, View.OnClickListener action) { Snackbar snack = Snackbar.make(findViewById(android.R.id.content), text, Snackbar.LENGTH_LONG) .setAction(actionName, action); View v = snack.getView(); v.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.accent)); ((TextView) v.findViewById(android.support.design.R.id.snackbar_text)).setTextColor(Color.WHITE); ((TextView) v.findViewById(android.support.design.R.id.snackbar_action)).setTextColor(Color.BLACK); snack.show(); }
Example 18
Source File: ForgotPasswordProvider.java From argus-android with Apache License 2.0 | 5 votes |
protected void showFailureDialog(String s) { //TODO need to create dialog box for handling error messages Snackbar snackbar = Snackbar.make(emailInput, s, Snackbar.LENGTH_SHORT); View view = snackbar.getView(); TextView textView= (TextView) view.findViewById(android.support.design.R.id.snackbar_text); textView.setMaxLines(2); snackbar.show(); }
Example 19
Source File: DialogFactory.java From android-base-mvp with Apache License 2.0 | 5 votes |
public static Snackbar showErrorSnackBar(Context mContext, View rootView, Throwable throwable) { String message = mContext.getString(R.string.dialog_general_error_message); if (throwable != null) { message = throwable.getLocalizedMessage(); } Snackbar snack_error = Snackbar.make(rootView, message, Snackbar.LENGTH_LONG); View view = snack_error.getView(); TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text); tv.setTextColor(ContextCompat.getColor(mContext, R.color.material_red)); return snack_error; }
Example 20
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; }