【问题标题】:How to add clickable website link into Snackbar?如何将可点击的网站链接添加到 Snackbar?
【发布时间】:2018-06-10 11:58:17
【问题描述】:

如何在 Snackbar Android 中添加可点击的网站链接?谢谢。

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

【问题讨论】:

    标签: android android-snackbar


    【解决方案1】:

    用这段代码sn-p替换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);
                  }
          }
    

    【讨论】:

      【解决方案2】:

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

      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();
      

      【讨论】:

        【解决方案3】:

        您不仅可以链接网站 URL,还可以使用此 LinkifyCustomized 类链接电子邮件地址、电话号码、@提及、主题标签和地图地址:

            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();
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2017-09-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-05-05
          • 1970-01-01
          • 2022-12-10
          • 1970-01-01
          相关资源
          最近更新 更多