Java Code Examples for android.support.design.widget.Snackbar#make()
The following examples show how to use
android.support.design.widget.Snackbar#make() .
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: TicketDetailActivity.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 2
Source File: CreateTicketActivity.java From faveo-helpdesk-android-app with Open Software License 3.0 | 6 votes |
/** * Display the snackbar if network connection is there. * * @param isConnected is a boolean value of network connection. */ private void showSnack(boolean isConnected) { if (isConnected) { Snackbar snackbar = Snackbar .make(findViewById(android.R.id.content), R.string.connected_to_internet, Snackbar.LENGTH_LONG); View sbView = snackbar.getView(); TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text); textView.setTextColor(Color.WHITE); snackbar.show(); } else { showSnackIfNoInternet(false); } }
Example 3
Source File: SnackbarUtil.java From FileManager with Apache License 2.0 | 6 votes |
public static void show(View view, String msg, int flag, final View.OnClickListener listener) { if (flag == 0) { // 短时显示 mSnackbar = Snackbar.make(view, msg, Snackbar.LENGTH_SHORT); } else { // 长时显示 mSnackbar = Snackbar.make(view, msg, Snackbar.LENGTH_LONG); } mSnackbar.show(); // mSnackbar.setActionTextColor(ContextCompat.getColor(view.getContext(), R.color.deepskyblue)); // Snackbar中有一个可点击的文字,这里设置点击所触发的操作 // 若监听不为空则执行监听的内容。 if(listener != null){ mSnackbar.setAction(R.string.certain, new View.OnClickListener() { @Override public void onClick(View v) { listener.onClick(v); mSnackbar.dismiss(); } }); } }
Example 4
Source File: ContactSelectActivity.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.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 5
Source File: UtilsDisplay.java From AppUpdater with Apache License 2.0 | 6 votes |
static Snackbar showUpdateAvailableSnackbar(final Context context, String content, Boolean indefinite, final UpdateFrom updateFrom, final URL apk) { Activity activity = (Activity) context; int snackbarTime = indefinite ? Snackbar.LENGTH_INDEFINITE : Snackbar.LENGTH_LONG; /*if (indefinite) { snackbarTime = Snackbar.LENGTH_INDEFINITE; } else { snackbarTime = Snackbar.LENGTH_LONG; }*/ Snackbar snackbar = Snackbar.make(activity.findViewById(android.R.id.content), content, snackbarTime); snackbar.setAction(context.getResources().getString(R.string.appupdater_btn_update), new View.OnClickListener() { @Override public void onClick(View view) { UtilsLibrary.goToUpdate(context, updateFrom, apk); } }); return snackbar; }
Example 6
Source File: CommonUtils.java From Awesome-WanAndroid with Apache License 2.0 | 6 votes |
/** * Show message * * @param activity Activity * @param msg message */ public static void showSnackMessage(Activity activity, String msg) { LogHelper.e("showSnackMessage :" + msg); //去掉虚拟按键 activity.getWindow().getDecorView().setSystemUiVisibility( //隐藏虚拟按键栏 | 防止点击屏幕时,隐藏虚拟按键栏又弹了出来 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE ); final Snackbar snackbar = Snackbar.make(activity.getWindow().getDecorView(), msg, Snackbar.LENGTH_SHORT); View view = snackbar.getView(); ((TextView) view.findViewById(R.id.snackbar_text)).setTextColor(ContextCompat.getColor(activity, R.color.white)); snackbar.setAction("知道了", v -> { snackbar.dismiss(); //隐藏SnackBar时记得恢复隐藏虚拟按键栏,不然屏幕底部会多出一块空白布局出来,很难看 activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); }).show(); snackbar.addCallback(new BaseTransientBottomBar.BaseCallback<Snackbar>() { @Override public void onDismissed(Snackbar transientBottomBar, int event) { super.onDismissed(transientBottomBar, event); activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); } }); }
Example 7
Source File: MapFragment.java From wikijourney_app with Apache License 2.0 | 6 votes |
private void drawMap() { // We get the POI around the user with WikiJourney API String url; url = gs.API_URL + "long=" + userLocation.getLongitude() + "&lat=" + userLocation.getLatitude() + "&maxPOI=" + paramMaxPoi + "&range=" + paramRange + "&lg=" + language; // Check if the Internet is up final ConnectivityManager connMgr = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); // These are needed for the download library and the methods called later final Context context = this.getActivity(); final MapFragment mapFragment = this; if (networkInfo != null && networkInfo.isConnected()) { // Show a Snackbar while we wait for WikiJourney server, so the user doesn't think the app crashed if (getActivity().findViewById(eu.wikijourney.wikijourney.R.id.fragment_container) != null) { downloadSnackbar = Snackbar.make(getActivity().findViewById(eu.wikijourney.wikijourney.R.id.fragment_container), eu.wikijourney.wikijourney.R.string.snackbar_downloading, Snackbar.LENGTH_INDEFINITE); downloadSnackbar.show(); } new DownloadWjApi(url, HomeFragment.METHOD_AROUND, context, mapFragment).invoke(false); } else { UI.openPopUp(mapFragment.getActivity(), getResources().getString(eu.wikijourney.wikijourney.R.string.error_activate_internet_title), getResources().getString(eu.wikijourney.wikijourney.R.string.error_activate_internet)); } }
Example 8
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 9
Source File: PitchPlayerFragment.java From Android-Guitar-Tuner with Apache License 2.0 | 5 votes |
@Override public void onErrorPlayingNote(@StringRes final int errorDescription, final boolean showAction, @StringRes final int errorAction, @ColorRes final int actionColor) { snackBar = Snackbar.make(containerConstraintLayout, errorDescription, Snackbar.LENGTH_INDEFINITE); if (showAction) { snackBar.setAction(errorAction, onClick -> presenter.retryPlayingNote(frequency)) .setActionTextColor(ContextCompat.getColor(getContext(), actionColor)); } snackBar.show(); }
Example 10
Source File: PostFragment.java From Hews with MIT License | 5 votes |
@Override public void showOfflineSnackBar() { snackbarNoConnection = Snackbar.make(layoutRoot, R.string.no_connection_prompt, Snackbar.LENGTH_INDEFINITE); Utils.setSnackBarTextColor(snackbarNoConnection, getActivity(), android.R.color.white); snackbarNoConnection.setAction(R.string.snackebar_action_retry, new View.OnClickListener() { @Override public void onClick(View v) { mPostPresenter.refresh(); } }); snackbarNoConnection.setActionTextColor(getResources().getColor(R.color.orange_600)); snackbarNoConnection.show(); }
Example 11
Source File: SendActivity.java From bcm-android with GNU General Public License v3.0 | 5 votes |
public void setTitle(String s) { if (title != null) { title.setText(s); Snackbar mySnackbar = Snackbar.make(coord, SendActivity.this.getResources().getString(R.string.detail_acc_name_changed_suc), Snackbar.LENGTH_SHORT); mySnackbar.show(); } }
Example 12
Source File: SingleFragmentActivity.java From timelapse-sony with GNU General Public License v3.0 | 5 votes |
@Override protected void onStart() { super.onStart(); FrameLayout frameLayout = findViewById(R.id.fragment_container); if(frameLayout != null && frameLayout.getChildCount() > 0) { mSnackBarConnectionLost = Snackbar.make(frameLayout.getChildAt(0), getString(R.string.connection_with_camera_lost), Snackbar.LENGTH_INDEFINITE); } else { mNotConnectedMessage = false; } }
Example 13
Source File: ActivityUtils.java From memetastic with GNU General Public License v3.0 | 4 votes |
public Snackbar showSnackBar(@StringRes int stringResId, boolean showLong) { Snackbar s = Snackbar.make(_activity.findViewById(android.R.id.content), stringResId, showLong ? Snackbar.LENGTH_LONG : Snackbar.LENGTH_SHORT); s.show(); return s; }
Example 14
Source File: ShareLocationActivity.java From Conversations with GNU General Public License v3.0 | 4 votes |
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.binding = DataBindingUtil.setContentView(this,R.layout.activity_share_location); setSupportActionBar((Toolbar) binding.toolbar); configureActionBar(getSupportActionBar()); setupMapView(binding.map, LocationProvider.getGeoPoint(this)); this.binding.cancelButton.setOnClickListener(view -> { setResult(RESULT_CANCELED); finish(); }); this.snackBar = Snackbar.make(this.binding.snackbarCoordinator, R.string.location_disabled, Snackbar.LENGTH_INDEFINITE); this.snackBar.setAction(R.string.enable, view -> { if (isLocationEnabledAndAllowed()) { updateUi(); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !hasLocationPermissions()) { requestPermissions(REQUEST_CODE_SNACKBAR_PRESSED); } else if (!isLocationEnabled()) { startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); } }); ThemeHelper.fix(this.snackBar); this.binding.shareButton.setOnClickListener(view -> { final Intent result = new Intent(); if (marker_fixed_to_loc && myLoc != null) { result.putExtra("latitude", myLoc.getLatitude()); result.putExtra("longitude", myLoc.getLongitude()); result.putExtra("altitude", myLoc.getAltitude()); result.putExtra("accuracy", (int) myLoc.getAccuracy()); } else { final IGeoPoint markerPoint = this.binding.map.getMapCenter(); result.putExtra("latitude", markerPoint.getLatitude()); result.putExtra("longitude", markerPoint.getLongitude()); } setResult(RESULT_OK, result); finish(); }); this.marker_fixed_to_loc = isLocationEnabledAndAllowed(); this.binding.fab.setOnClickListener(view -> { if (!marker_fixed_to_loc) { if (!isLocationEnabled()) { startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { requestPermissions(REQUEST_CODE_FAB_PRESSED); } } toggleFixedLocation(); }); }
Example 15
Source File: TravelmateSnackbars.java From Travel-Mate with MIT License | 4 votes |
static Snackbar createSnackBar(View view, int message, int duration) { return Snackbar.make(view, message, duration); }
Example 16
Source File: BaseFragment.java From Melophile with Apache License 2.0 | 4 votes |
protected void showMessage(@StringRes int res) { if (getView() != null) { Snackbar.make(getView(), res, getResources().getInteger(R.integer.message_duration)); } }
Example 17
Source File: WebFragment.java From PowerFileExplorer with GNU General Public License v3.0 | 4 votes |
@Override public void onClick(View v) { int viewId = v.getId(); if (viewId == R.id.close) { if (rtl) { showMenu(); // } else { // exitActivity(); } } else if (viewId == R.id.back) { if (rtl) { webView.goForward(); } else { webView.goBack(); } } else if (viewId == R.id.forward) { if (rtl) { webView.goBack(); } else { webView.goForward(); } } else if (viewId == R.id.more) { if (rtl) { //exitActivity(); } else { showMenu(); } } else if (viewId == R.id.menuLayout) { hideMenu(); } else if (viewId == R.id.menuRefresh) { webView.reload(); hideMenu(); } else if (viewId == R.id.menuFind) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) webView.showFindDialog("", true); hideMenu(); } else if (viewId == R.id.menuShareVia) { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, webView.getUrl()); sendIntent.setType("text/plain"); startActivity(Intent.createChooser(sendIntent, getResources().getString(stringResShareVia))); hideMenu(); } else if (viewId == R.id.menuCopyLink) { ClipboardManagerUtil.setText(webView.getUrl()); Snackbar snackbar = Snackbar.make(coordinatorLayout, getString(stringResCopiedToClipboard), Snackbar.LENGTH_LONG); View snackbarView = snackbar.getView(); snackbarView.setBackgroundColor(toolbarColor); if (snackbarView instanceof ViewGroup) updateChildTextView((ViewGroup) snackbarView); snackbar.show(); hideMenu(); } else if (viewId == R.id.menuOpenWith) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(webView.getUrl())); startActivity(browserIntent); hideMenu(); } }
Example 18
Source File: ActivityUtils.java From kimai-android with MIT License | 4 votes |
public Snackbar showSnackBar(@StringRes int stringResId, boolean showLong) { Snackbar s = Snackbar.make(_activity.findViewById(android.R.id.content), stringResId, showLong ? Snackbar.LENGTH_LONG : Snackbar.LENGTH_SHORT); s.show(); return s; }
Example 19
Source File: SnackbarUtils.java From YiZhi with Apache License 2.0 | 3 votes |
/** * 长显示Snackbar,自定义颜色 * * @param view * @param message * @param messageColor * @param backgroundColor * @return */ public static Snackbar getLong(View view, String message, int messageColor, int backgroundColor) { Snackbar snackbar = Snackbar.make(view, message, Snackbar.LENGTH_LONG); setSnackbarColor(snackbar, messageColor, backgroundColor); return snackbar; }
Example 20
Source File: SnackbarUtils.java From YiZhi with Apache License 2.0 | 2 votes |
/** * 短显示Snackbar,可选预设类型 * * @param view * @param message * @param type * @return */ public static Snackbar getShort(View view, String message, int type) { Snackbar snackbar = Snackbar.make(view, message, Snackbar.LENGTH_SHORT); switchType(snackbar, type); return snackbar; }