Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EJunWhite/2f58d98c97ce97bc597513625e2fce11 to your computer and use it in GitHub Desktop.
Save EJunWhite/2f58d98c97ce97bc597513625e2fce11 to your computer and use it in GitHub Desktop.
Snackbar snackbar;
mBinding.searchEdit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
hideSnackBar();
}
});
mBinding.searchEdit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
hideSnackBar();
}
});
void showSnackBar(View view, String message, int duration) {
hideSnackBar();
if (snackbar == null) {
snackbar = Snackbar.make(view, message, duration);
}
snackbar.setActionTextColor(getResources().getColor(android.R.color.white));
View snackbarView = snackbar.getView();
int snackbarTextId = android.support.design.R.id.snackbar_text;
TextView textView = (TextView) snackbarView.findViewById(snackbarTextId);
// FIXME : Fixed Font
Typeface custom_font = ResourcesCompat.getFont(getActivity(), com.ejun.library.R.font.noto_sans_kr_regular);
textView.setIncludeFontPadding(false);
textView.setTypeface(custom_font);
textView.setTextColor(getActivity().getResources().getColor(android.R.color.white));
snackbarView.setBackgroundColor(Color.BLACK);
snackbar.getView().setVisibility(View.VISIBLE);
snackbar.show();
}
void hideSnackBar() {
if (snackbar != null) {
snackbar.getView().setVisibility(View.GONE);
snackbar.dismiss();
}
snackbar = null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment