当前位置: 首页>>代码示例>>Java>>正文


Java Snackbar.show方法代码示例

本文整理汇总了Java中android.support.design.widget.Snackbar.show方法的典型用法代码示例。如果您正苦于以下问题:Java Snackbar.show方法的具体用法?Java Snackbar.show怎么用?Java Snackbar.show使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.design.widget.Snackbar的用法示例。


在下文中一共展示了Snackbar.show方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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();
}
 
开发者ID:pan2yong22,项目名称:AndroidUtilCode-master,代码行数:34,代码来源:SnackbarUtils.java

示例2: showRequestPermissionRationale

import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
private void showRequestPermissionRationale() {
    Snackbar snackbar = Snackbar.make(
            view,
            getString(R.string.permission_info),
            Snackbar.LENGTH_INDEFINITE)
            .setAction(getString(R.string.permission_ok), new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ActivityCompat.requestPermissions(
                            HelperActivity.this,
                            permissions,
                            ConstantsCustomGallery.PERMISSION_REQUEST_CODE);
                }
            });

    /*((TextView) snackbar.getView()
            .findViewById(android.support.design.R.id.snackbar_text)).setMaxLines(maxLines);*/
    snackbar.show();
}
 
开发者ID:myinnos,项目名称:AwesomeImagePicker,代码行数:20,代码来源:HelperActivity.java

示例3: onActivityResult

import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
@Override
protected void onActivityResult(int request, int result, Intent data) {
	super.onActivityResult(request, result, data);

	if (request == REQUEST_INTRODUCTION && result == RESULT_OK) {
		Snackbar snackbar = Snackbar.make(list, R.string.introduction_sent,
				Snackbar.LENGTH_SHORT);
		snackbar.getView().setBackgroundResource(R.color.briar_primary);
		snackbar.show();
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:12,代码来源:ConversationActivity.java

示例4: onLinkClicked

import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
@Override
public void onLinkClicked(String url) {
    // Handle links to post internally
    if(url.startsWith(FEFE_BASE_URL)) {
        try {
            Log.d(TAG, "Clicked on link to post, try to handle it internally");
            String postId = url.substring(FEFE_BASE_URL.length());
            Post post = databaseWrapper.getPost(postId);

            Intent intent = createShowPostIntent(this, post);
            startActivity(intent);
            return;
        }
        catch(DatabaseException e) {
            Log.d(TAG, "Post is not stored, following normal procedure");
        }
    }

    // Start intent with optional preview
    final Intent urlIntent = new Intent(Intent.ACTION_VIEW);
    urlIntent.setData(Uri.parse(url));
    if(preferenceHelper.isUrlInspectionEnabled()) {
        Snackbar snackbar = Snackbar.make(postView, url, Snackbar.LENGTH_INDEFINITE);
        snackbar.setAction(R.string.button_open_link, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(urlIntent);
            }
        });
        snackbar.show();
    }
    else {
        startActivity(urlIntent);
    }
}
 
开发者ID:tbolender,项目名称:fefereader,代码行数:36,代码来源:DetailsActivity.java

示例5: createRefreshSnackbar

import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
/**
 * 创建 正在刷新... - 上次刷新时间 Snackbar(用 SharedPreferences 保存上次刷新时间)
 *
 * @param view ViewGroup 子类
 * @param str  记录上次刷新时间的标记:统一用TAG
 */
public void createRefreshSnackbar(ViewGroup view, String str) {
    String currentDate = DateUtil.longDateToStrMDHMS(System.currentTimeMillis());
    SharedPreferences spRefreshDate = getSharedPreferences(AppDelegate.SP_REFRESH_DATE, Context.MODE_PRIVATE);
    String lastRefreshDate = spRefreshDate.getString(str, currentDate);
    Snackbar snackbar = Snackbar.make(view, "正在刷新...", Snackbar.LENGTH_SHORT);
    snackbar.setAction("上次刷新时间:" + lastRefreshDate, new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // 这个点击事件必须加上不然 snackbar_action 就无法显示
            // snackbar.dismiss();
        }
    });
    TextView snackbar_action = (TextView) snackbar.getView().findViewById(R.id.snackbar_action);
    snackbar_action.setTextSize(11f);
    snackbar.setActionTextColor(getColors(R.color.white));
    Snackbar.SnackbarLayout snackBarLayout = (Snackbar.SnackbarLayout) snackbar.getView();
    snackBarLayout.setBackgroundColor(getColors(R.color.color_theme));
    snackBarLayout.setAlpha(0.9f);
    snackbar.show();
    spRefreshDate.edit().putString(str, currentDate).commit();
}
 
开发者ID:jpaijh,项目名称:TYT,代码行数:28,代码来源:BaseActivity.java

示例6: handleMessage

import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
@Override
public void handleMessage(Message message) {
    MinorChooserFragment minorChooserFragment = minorChooserFragmentWeakReference.get();
    final Snackbar snackbar = Snackbar.make(minorChooserFragment.getActivity().findViewById(R.id.minor_chooser), minorChooserFragment.getString(R.string.first_minor_is) + " " +
            String.valueOf(message.getData().getInt("REX") + 1) + " , " +
            String.valueOf(message.getData().getInt("REY") + 1) + " is : " +
            minorChooserFragment.GetText(message.getData().getFloat("VALUE")), Snackbar.LENGTH_INDEFINITE);
    snackbar.show();
    snackbar.setAction(minorChooserFragment.getString(R.string.cancel), new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            snackbar.dismiss();
        }
    });
}
 
开发者ID:coder3101,项目名称:Matrix-Calculator-for-Android,代码行数:16,代码来源:MinorChooserFragment.java

示例7: onReceive

import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    boolean response1 = intent.getBooleanExtra("response",true);
    if((!response1) && (response1 != response)){
        Snackbar sb = Snackbar.make(findViewById(R.id.resetPasswordConstraintLayout), "Oops, No data connection?", Snackbar.LENGTH_LONG);
        View v = sb.getView();
        v.setBackgroundColor(ContextCompat.getColor(getApplication(), R.color.colorPrimary));
        sb.show();
    }
    response = response1;
}
 
开发者ID:Socialate,项目名称:furry-sniffle,代码行数:12,代码来源:ResetPasswordActivity.java

示例8: showError

import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
@Override
public void showError(@NonNull String title, String error) {
    Log.e(TAG, error != null ? error : title);
    Snackbar snackbar = Snackbar.make(mLayout, title, Snackbar.LENGTH_INDEFINITE);
    snackbar.show();

}
 
开发者ID:googlecodelabs,项目名称:security-config,代码行数:8,代码来源:MainFragment.java

示例9: saveImage

import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
public void saveImage() {
    if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
    } else {
        Bitmap                bitmap = view.bitmap;
        ByteArrayOutputStream bytes  = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
        try {
            new File(getDirectory()).mkdirs();
            final File image = new File(getDirectory() + getFilename());
            image.createNewFile();
            FileOutputStream outputStream = new FileOutputStream(image);
            outputStream.write(bytes.toByteArray());
            outputStream.close();
            final Snackbar snackbar = Snackbar.make(findViewById(R.id.coordinatorLayout), "Saved as " + getFilename(), Snackbar.LENGTH_LONG);
            snackbar.setAction("Open", new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    snackbar.dismiss();
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setDataAndType(Uri.fromFile(image), "image/jpeg");
                    if (intent.resolveActivity(getPackageManager()) != null) {
                        startActivity(intent);
                    }
                }
            });
            snackbar.show();
        } catch (IOException e) {
            Utils.logError(e);
        }
    }
}
 
开发者ID:LCA311,项目名称:leoapp-sources,代码行数:33,代码来源:StundenplanBildActivity.java

示例10: doErrorDialog

import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
private void doErrorDialog(@StringRes int descriptionId, @StringRes int actionId,
                           View.OnClickListener listener) {
    if (anyView != null) {
        Snackbar bar = Snackbar.make(anyView, getString(descriptionId),
                Snackbar.LENGTH_SHORT);
        bar.setAction(actionId, listener);
        bar.show();
    }
}
 
开发者ID:Vavassor,项目名称:Tusky,代码行数:10,代码来源:ViewMediaActivity.java

示例11: 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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:34,代码来源:SnackbarUtils.java

示例12: doBack

import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
public void doBack() {
    //BackPressed in activity will call this;
    Snackbar snackbar = Snackbar
            .make(listView, getString(R.string.toast_exit), Snackbar.LENGTH_SHORT)
            .setAction(getString(R.string.toast_yes), new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    getActivity().finish();
                }
            });
    snackbar.show();
}
 
开发者ID:JaeNuguid,项目名称:Kids-Portal-Android,代码行数:13,代码来源:Fragment_Reports.java

示例13: showPermissionMessage

import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
@Override
public void showPermissionMessage(int resId) {
    final Snackbar snackbar = Snackbar.make(rlRoot, resId, Snackbar.LENGTH_INDEFINITE);
    snackbar.setAction(R.string.button_settings, new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            presenter.showAppSystemSettings();
            snackbar.dismiss();
        }
    });
    snackbar.show();
}
 
开发者ID:vshkl,项目名称:PXLSRT,代码行数:13,代码来源:CameraActivity.java

示例14: showSnackBar

import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
/**
 * (头部)
 *
 * @param container
 * @param msg
 * @param length
 */
public void showSnackBar(View container, String msg, int length) {
    Snackbar snackbar = Snackbar.make(container, msg, length);
    View view = snackbar.getView();
    //对两个控件进行自定义设置
    view.setBackgroundColor(getResources().getColor(R.color.black_414040));
    snackbar.show();
}
 
开发者ID:haihaio,项目名称:AmenEye,代码行数:15,代码来源:BaseActivity.java

示例15: 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();
}
 
开发者ID:fekracomputers,项目名称:IslamicLibraryAndroid,代码行数:14,代码来源:BrowsingActivity.java


注:本文中的android.support.design.widget.Snackbar.show方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。