如何将可点击的网站 link 添加到 Snackbar?

How to add clickable website link into Snackbar?

如何将可点击的网站 link 添加到 Snackbar Android 中?谢谢

        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_SHORT)
                    .setAction("Action", null).show();

用此代码段替换 null。

  new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                       Intent browserIntent = new 
                       Intent(Intent.ACTION_VIEW, 
                       Uri.parse(getString(R.string.page_address)));
                       startActivity(browserIntent);
              }
      }

试试这个.....它对我有用

Snackbar snackbar = Snackbar.make(view, "www.google.com", Snackbar.LENGTH_LONG);
Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) 
snackbar.getView();

TextView textView = (TextView) layout.findViewById(android.support.design.R.id.snackbar_text);
       textView.setAutoLinkMask(Linkify.ALL);
       textView.setMovementMethod(LinkMovementMethod.getInstance());
       snackbar.show();

您不仅可以链接网站 URL,还可以链接电子邮件地址、phone 数字、@提及、主题标签和地图地址 LinkifyCustomized class:

    Snackbar snackbar = Snackbar.make(viewGroup, message, duration);
    final View snackBarView = snackbar != null ? snackbar.getView() : null;
    final TextView tv = snackbar != null? snackBarView.findViewById(R.id.snackbar_text) : null;
    LinkifyCustomized.addLinks(tv, LinkifyCustomized.WEB_URLS | LinkifyCustomized.EMAIL_ADDRESSES);
    snackbar.show();