This is the simple way I use
Strings In strings.xml
<?xml version="1.0" encoding="utf-8"?> <resources xmlns:tools="http://schemas.android.com/tools"> <string name="credits_title">Credits</string> <string name="confirm">OK</string> <string name="credits">All rights reserved. <a href="https://google.com">Source</a> </string> </resources>
Dimensions In dimens.xml
<?xml version="1.0" encoding="utf-8"?> <resources xmlns:tools="http://schemas.android.com/tools"> <dimen name="margin_8dp">8dp</dimen> <dimen name="margin_32dp">32dp</dimen> </resources>
Helper Dialog class
public class MessageHelper { public static void showCreditsDialog(Context context) { AlertDialog alertDialog = new AlertDialog.Builder(context).create(); alertDialog.setTitle(R.string.credits_title); TextView textView = new TextView(context); int padding = (int) context.getResources().getDimension(R.dimen.margin_32dp); int topPadding = (int) context.getResources().getDimension(R.dimen.margin_8dp); textView.setPadding(padding, topPadding, padding, 0); textView.setMovementMethod(LinkMovementMethod.getInstance()); textView.setText(R.string.credits); alertDialog.setView(textView); alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, context.getResources().getString(R.string.confirm), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialog.show(); } }
How to use
MessageHelper.showCreditsDialog(this); // this is the context
Preview
