本文整理汇总了Java中android.support.design.widget.Snackbar.addCallback方法的典型用法代码示例。如果您正苦于以下问题:Java Snackbar.addCallback方法的具体用法?Java Snackbar.addCallback怎么用?Java Snackbar.addCallback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.design.widget.Snackbar
的用法示例。
在下文中一共展示了Snackbar.addCallback方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DoubleClickCloseSnackBar
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
public static void DoubleClickCloseSnackBar(final Activity mActivity, boolean isDoubleClick) {
if (isDoubleClick && waitDoubleClick) {
mActivity.finish();
} else {
Snackbar snackbar = Snackbar.make(mActivity.findViewById(R.id.main_layout_content), R.string.action_warn_double_click_close_application, Snackbar.LENGTH_SHORT);
snackbar.addCallback(new BaseTransientBottomBar.BaseCallback<Snackbar>() {
@Override
public void onDismissed(Snackbar transientBottomBar, int event) {
waitDoubleClick = false;
super.onDismissed(transientBottomBar, event);
}
});
waitDoubleClick = true;
snackbar.show();
}
}
示例2: remove
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
/**
* Performs the action on the specified positions and displays a SnackBar to Undo
* the operation. To customize the UPDATE event, please set a custom listener with
* {@link #withAction(int, OnActionListener)} method.
* <p>By default the DELETE action will be performed.</p>
*
* @param positions the position to delete or update
* @param mainView the view to find a parent from
* @param message the text to show. Can be formatted text
* @param actionText the action text to display
* @param undoTime How long to display the message. Either {@link Snackbar#LENGTH_SHORT} or
* {@link Snackbar#LENGTH_LONG} or any custom Integer.
* @return The SnackBar instance
* @see #remove(List, View, int, int, int)
*/
@SuppressWarnings("WrongConstant")
public Snackbar remove(List<Integer> positions, @NonNull View mainView,
CharSequence message, CharSequence actionText,
@IntRange(from = -1) int undoTime) {
this.mPositions = positions;
Snackbar snackbar;
if (!mAdapter.isPermanentDelete()) {
snackbar = Snackbar.make(mainView, message, undoTime > 0 ? undoTime + 400 : undoTime)
.setAction(actionText, new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mUndoListener != null)
mUndoListener.onUndoConfirmed(mAction);
}
});
} else {
snackbar = Snackbar.make(mainView, message, undoTime);
}
if (mActionTextColor != Color.TRANSPARENT) {
snackbar.setActionTextColor(mActionTextColor);
}
snackbar.addCallback(this);
snackbar.show();
return snackbar;
}
示例3: showSnackbar
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
public static void showSnackbar(View container, @NonNull SnackbarType snackbarType,
@StringRes int textStringRes, @Nullable SnackbarDuration duration,
@Nullable BaseTransientBottomBar.BaseCallback<Snackbar> callback) {
duration = (duration == null ? SnackbarDuration.LONG : duration);
Snackbar snackbar = Snackbar.make(container, textStringRes, duration.getDuration());
snackbar.getView().setBackgroundResource(snackbarType.getColorRes());
TextView snackbarText = (TextView) snackbar.getView().findViewById(android.support.design.R.id.snackbar_text);
snackbarText.setCompoundDrawablesWithIntrinsicBounds(0, 0,snackbarType.getIconRes(), 0);
snackbarText.setGravity(Gravity.CENTER);
if(callback != null)
snackbar.addCallback(callback);
snackbar.show();
}
示例4: removeItemWithSnackbar
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
public void removeItemWithSnackbar(Activity activity, final int position, final SnackbarListener listener)
{
getSwipeManager().performFakeSwipe(mVHs.get(position), SwipeableItemConstants.RESULT_SWIPED_LEFT);
if (mChatroomObjects.get(position) != null)
{
final ChatroomRecyclerObject huehuehue = removeItem(position);
if (huehuehue != null)
{
final SharedPreferences mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(activity);
huehuehue.setIsPinned(false);
String chatroomName = huehuehue.getName();
String snackTextDel = "Deleted " + chatroomName;
final String snackTextRestore = "Chatroom restored!";
final SpannableStringBuilder snackTextDelSSB = new SpannableStringBuilder().append(snackTextDel);
final SpannableStringBuilder snackTextRestoreSSB = new SpannableStringBuilder().append(snackTextRestore);
if (mSharedPrefs.getBoolean("darkTheme", false))
{
snackTextDelSSB.setSpan(new ForegroundColorSpan(activity.getResources().getColor(R.color.colorDark)), 0, snackTextDel.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
snackTextRestoreSSB.setSpan(new ForegroundColorSpan(activity.getResources().getColor(R.color.colorDark)), 0, snackTextRestore.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
else
{
snackTextDelSSB.setSpan(new ForegroundColorSpan(activity.getResources().getColor(R.color.white)), 0, snackTextDel.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
snackTextRestoreSSB.setSpan(new ForegroundColorSpan(activity.getResources().getColor(R.color.white)), 0, snackTextRestore.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
final View parentLayout = activity.findViewById(android.R.id.content);
Snackbar snackbar = Snackbar
.make(parentLayout, snackTextDelSSB, Snackbar.LENGTH_LONG)
.setAction("UNDO", new View.OnClickListener()
{
@Override
public void onClick(View view)
{
Snackbar hue = Snackbar.make(parentLayout, snackTextRestoreSSB, Snackbar.LENGTH_SHORT);
if (mSharedPrefs.getBoolean("darkTheme", false))
{
hue.getView().setBackgroundColor(Color.WHITE);
}
hue.show();
addItem(huehuehue);
listener.onUndo();
}
});
if (mSharedPrefs.getBoolean("darkTheme", false))
{
snackbar.getView().setBackgroundColor(activity.getResources().getColor(R.color.white));
}
snackbar.show();
snackbar.addCallback(new BaseTransientBottomBar.BaseCallback<Snackbar>()
{
@Override
public void onDismissed(Snackbar transientBottomBar, int event)
{
switch (event)
{
case DISMISS_EVENT_TIMEOUT:
listener.onUndoExpire(huehuehue.getUrl());
break;
}
}
});
}
}
}