1
The goal is to create a dialog with some links to websites.
The following code already does this, but the URL appear explicitly (www....) and I would like it to be 'hidden' behind words like 'click here'.
public void show() {
PackageInfo versionInfo = getPackageInfo();
String EULA_PREFIX = "eula_";
final SpannableString how = new SpannableString(mActivity.getString(R.string.url_how));
final SpannableString privacy = new SpannableString(mActivity.getString(R.string.url_privacy));
final SpannableString terms = new SpannableString(mActivity.getString(R.string.url_terms));
final String eulaKey = EULA_PREFIX + versionInfo.versionCode;
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mActivity);
boolean hasBeenShown = prefs.getBoolean(eulaKey, false);
TextView textView = new TextView(mActivity);
textView.setText(mActivity.getString(R.string.eula_updates) + "\n\n"
+ mActivity.getString(R.string.str_how) + how + "\n\n"
+ mActivity.getString(R.string.str_privacy) + privacy + "\n\n"
+ mActivity.getString(R.string.str_terms) + terms + "\n\n"
+ mActivity.getString(R.string.str_agree)
);
textView.setAutoLinkMask(RESULT_OK);
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setPadding(8, 8, 8, 8);
Linkify.addLinks(textView, Linkify.WEB_URLS);
String title = mActivity.getString(R.string.app_name) + " v" + versionInfo.versionName;
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity)
.setTitle(title)
.setView(textView)
.setPositiveButton(R.string.button_agree, new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(eulaKey, true);
editor.apply();
dialogInterface.dismiss();
}
})
.setNegativeButton(R.string.button_disagree, new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mActivity.finish();
}
});
builder.create().show();
}
To make it clear, if it were HTML, you would get this effect like this:
<a href="www.exemplo.com">clique aqui</a>
So the link works, but what the user sees and touches is the expression 'click here'
Stretch of string.xml
<string name="eula_updates">Updates in this version: Test version. Updates and bugs.</string>
<string name="url_how">https://www.exemplo.com/index.html#header3-2</string>
<string name="url_privacy">https://www.exemplo.com/index.html#header3-6</string>
<string name="url_terms">https://www.exemplo.com.br/index.html#content5-9</string>
<string name="str_how">How to use MOTONOIX </string>
<string name="str_privacy">MOTONOIX privacy policy </string>
<string name="str_terms">MOTONOIX Terms of Use here </string>
<string name="str_agree">By clicking the button to continue, you declare that you are in compliance with this policy and the terms presented</string>
You can do this on Android?
was your tip that gave me the answer, but since there are several links and texts, I decided to add a response with modified code, including the
strings.xml
which I also added to the question to compare the versions. Thank you again. You are great!– Rene Freak