本文整理汇总了Java中android.support.design.widget.Snackbar.setAction方法的典型用法代码示例。如果您正苦于以下问题:Java Snackbar.setAction方法的具体用法?Java Snackbar.setAction怎么用?Java Snackbar.setAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.design.widget.Snackbar
的用法示例。
在下文中一共展示了Snackbar.setAction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showUpdateAvailableSnackbar
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
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;
}
示例2: maybeShowUriOverrideReminder
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
private void maybeShowUriOverrideReminder() {
if (ImageUriProvider.getInstance(this).getUriOverride() == null) {
return;
}
final Snackbar snackbar = Snackbar.make(
findViewById(R.id.content_main),
R.string.snackbar_uri_override_reminder_text,
Snackbar.LENGTH_LONG);
snackbar.setAction(
R.string.snackbar_uri_override_reminder_change_button,
new View.OnClickListener() {
@Override
public void onClick(View view) {
showFragment(new SettingsFragment());
}
});
snackbar.show();
}
示例3: onPostExecute
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
@Override
protected void onPostExecute(Boolean b) {
if (b) {
dismiss();
Toast.makeText(Utils.getContext(), "Umfrage erfolgreich erstellt", Toast.LENGTH_LONG).show();
} else {
final Snackbar snackbar = Snackbar.make(findViewById(R.id.wrapper), "Es ist etwas schiefgelaufen, versuche es später erneut", Snackbar.LENGTH_SHORT);
snackbar.setActionTextColor(ContextCompat.getColor(getContext(), R.color.colorPrimary));
snackbar.setAction(getContext().getString(R.string.dismiss), new View.OnClickListener() {
@Override
public void onClick(View v) {
snackbar.dismiss();
}
});
snackbar.show();
}
}
示例4: show
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
/**
* 设置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();
}
示例5: deleteSchedule
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
private void deleteSchedule() {
final Snackbar snackbar = Snackbar.make(findViewById(R.id.fragmentPlaceHolder), "Delete " + loadedSchedule.getLanguage() + "?\n(Can't be undone!)", Snackbar.LENGTH_INDEFINITE);
snackbar.setAction("Delete", view -> {
// find array index of the currently loaded schedule
int position = schedules.indexOf(loadedSchedule);
// delete the schedule
realm.executeTransaction(r -> {
schedules.deleteFromRealm(position);
});
// update the side menu
navigationAdapter.notifyItemRemoved(position);
// load the next schedule if there's one left
int newPosition = position > 0 ? position - 1 : position;
if (schedules.size() > 0) {
loadMainFragment(schedules.get(newPosition));
} else {
loadNewScheduleActivity(false);
}
snackbar.dismiss();
});
snackbar.show();
}
示例6: show
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
public 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();
}
示例7: requestWriteExternalPermission
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
/**
* Request for permission
* If permission denied or app is first launched, request for permission
* If permission denied and user choose 'Nerver Ask Again', show snackbar with an action that navigate to app settings
*/
private void requestWriteExternalPermission() {
Log.w(TAG, "Write External permission is not granted. Requesting permission");
final String[] permissions = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE};
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
ActivityCompat.requestPermissions(this, permissions,Constants.PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
} else {
if (!isPermissionRequested(Constants.PREF_WRITE_EXTERNAL_STORAGE_REQUESTED)) {
ActivityCompat.requestPermissions(this, permissions,Constants.PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
setPermissionRequested(Constants.PREF_WRITE_EXTERNAL_STORAGE_REQUESTED);
} else {
Snackbar snackbar = Snackbar.make(mainLayout, R.string.msg_no_write_external_permission,
Snackbar.LENGTH_INDEFINITE);
snackbar.setAction(R.string.ok, new View.OnClickListener() {
@Override
public void onClick(View view) {
openAppSettings();
}
});
snackbar.show();
}
}
}
示例8: showSnackBar
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
public void showSnackBar(String text, int duration){
final Snackbar snackbar = Snackbar.make(findViewById(R.id.content_view), text, duration);
snackbar.setAction(android.R.string.ok, new View.OnClickListener() {
@Override
public void onClick(View view) {
snackbar.dismiss();
}
});
snackbar.setActionTextColor(SettingsActivity.getPrimaryColor()).show();
}
示例9: onFailure
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
@Override
public void onFailure(Call<Character> call, Throwable t) {
final Snackbar snackbar = Snackbar.make(coordinatorLayout, R.string.text_error_request, Snackbar.LENGTH_INDEFINITE);
snackbar.setAction(R.string.Retry, new View.OnClickListener() {
@Override
public void onClick(View view) {
requestCharacterInfo();
snackbar.dismiss();
}
});
snackbar.show();
}
示例10: show
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
/**
* 显示snackbar
*/
public void show() {
final View view = parent;
if (view == null) return;
if (messageColor != COLOR_DEFAULT) {
SpannableString spannableString = new SpannableString(message);
ForegroundColorSpan colorSpan = new ForegroundColorSpan(messageColor);
spannableString.setSpan(colorSpan, 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
snackbarWeakReference = new WeakReference<>(Snackbar.make(view, spannableString, duration));
} else {
snackbarWeakReference = new WeakReference<>(Snackbar.make(view, message, duration));
}
final Snackbar snackbar = snackbarWeakReference.get();
final View snackbarView = snackbar.getView();
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();
}
示例11: showSnackbar
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
private static Snackbar showSnackbar(View view, String message,
@StringRes int actionLabel,
View.OnClickListener clickListener) {
Snackbar snackbar = Snackbar.make(view, message.trim(), Snackbar.LENGTH_INDEFINITE);
if (clickListener != null) {
snackbar.setAction(actionLabel, clickListener);
}
snackbar.show();
return snackbar;
}
示例12: requestReadExternalStorage
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
public boolean requestReadExternalStorage(final int requestType) {
// permission to read external storage granted
if (ActivityCompat.checkSelfPermission(mActivity,
Manifest.permission.READ_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
return true;
}
// permission to read external storage not granted
else {
if (ActivityCompat.shouldShowRequestPermissionRationale(mActivity, Manifest.permission.READ_EXTERNAL_STORAGE)) {
// ask for permission and explain why
Snackbar snackbar = Snackbar.make(mRootView, mActivity.getString(R.string.snackbar_request_storage_access), Snackbar.LENGTH_INDEFINITE);
snackbar.setAction(R.string.dialog_generic_button_okay, new View.OnClickListener() {
@Override
public void onClick(View view) {
ActivityCompat.requestPermissions(mActivity, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, requestType);
}
});
snackbar.show();
return false;
} else {
// ask for permission without explanation
ActivityCompat.requestPermissions(mActivity, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, requestType);
return false;
}
}
}
示例13: notifyBookDownloadFailed
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
private void notifyBookDownloadFailed(int bookId, String failurReason) {
CoordinatorLayout coordinatorLayout = findViewById(R.id.browsing_coordinator_layout);
Snackbar mySnackbar = Snackbar.make(coordinatorLayout,
getResources().getString(R.string.book_download_failure, mBooksInformationDbHelper.getBookName(bookId)),
Snackbar.LENGTH_LONG);
mySnackbar.setAction(R.string.redownload,
v -> {
bookCardEventsCallback.startDownloadingBook(mBooksInformationDbHelper.getBookInfo(bookId));
bookCardEventsCallback.notifyBookDownloadStatusUpdate(bookId, DownloadsConstants.STATUS_DOWNLOAD_REQUESTED);
}
);
mySnackbar.show();
}
示例14: showSnackBarBookNotDownloaded
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
@Override
public void showSnackBarBookNotDownloaded(int bookId) {
CoordinatorLayout coordinatorLayout = findViewById(R.id.browsing_coordinator_layout);
Snackbar mySnackbar = Snackbar.make(coordinatorLayout,
getResources().getString(R.string.book_not_download, mBooksInformationDbHelper.getBookName(bookId)),
Snackbar.LENGTH_LONG);
mySnackbar.setAction(R.string.redownload,
v -> {
bookCardEventsCallback.startDownloadingBook(mBooksInformationDbHelper.getBookInfo(bookId));
bookCardEventsCallback.notifyBookDownloadStatusUpdate(bookId, DownloadsConstants.STATUS_DOWNLOAD_REQUESTED);
}
);
mySnackbar.show();
}
示例15: EnforceRefresh
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
private void EnforceRefresh() {
Snackbar snackbar = Snackbar.make(findViewById(R.id.MainContent), R.string.EnforceRef, Snackbar.LENGTH_INDEFINITE);
snackbar.setAction(R.string.Refresh, new View.OnClickListener() {
@Override
public void onClick(View view) {
((GlobalValues) getApplication()).matrixAdapter.notifyDataSetChanged();
}
});
snackbar.show();
}