Android-Is it possible to add a clickable link into a string resource

后端 未结 4 507
太阳男子
太阳男子 2021-02-01 01:27

I usually set up some kind of AlertDialog to fire off when a user first uses one of my apps and I explain how to use the app and give an overall introduction to wha

4条回答
  •  清酒与你
    2021-02-01 02:05

    Android doesn't make strings that contain valid link clickable automatically. What you can do, is add custom view to your dialog and use WebView to show the alert message. In that case, you can store html in your resources and they will be clickable.

    View alertDialogView = LayoutInflater.inflate(R.layout.alert_dialog_layout, null);
    
    WebView myWebView = (WebView) alertDialogView.findViewById(R.id.dialogWebView);
    myWebView.loadData("Google!", "text/html", "utf-8");
    AlertDialog.Builder builder = new AlertDialog.Builder(MyActivity.this);
    builder.setView(alertDialogView);
    

    alert_dialog_layout.xml

    
    
    

提交回复
热议问题