Add http://www. in the text if not Exist

前端 未结 6 619
迷失自我
迷失自我 2021-02-08 21:31

How can I know that some text contain \"http://www.\" I want to show domain in Web View. Domain name is written in TextView but there is no restriction to add prefix. If user di

6条回答
  •  有刺的猬
    2021-02-08 21:54

    You can do like this

    String url = textView.getText().toString();
    if(!url.startsWith("www.")&& !url.startsWith("http://")){
      url = "www."+url;
    }
    if(!url.startsWith("http://")){
      url = "http://"+url;
    }
    

    You can use this url to display content in WebView

    Hope this will solve your problem

提交回复
热议问题