I'm trying to set the linktextcolor of the message in AlertDialog. But when I try to findViewById my app crashes. What am I doing wrong? Do I need to have message in the XML for the activity?
final AlertDialog d = new AlertDialog.Builder(new ContextThemeWrapper(SplashPage.this, R.style.Theme_Sherlock_Light_Dialog))
.setIcon(android.R.drawable.ic_dialog_info).setTitle(getString(R.string.termsTitle))
//.setView(message).setCancelable(false)
.setMessage(Html.fromHtml(getString(R.string.terms))).setCancelable(false)
.setPositiveButton(getString(R.string.accept), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
app.setTermsAccepted(true);
dialogInterface.dismiss();
Intent intent = new Intent(SplashPage.this, LoginPage.class);
startActivity(intent);
}
}).create();
//FAILING: TextView TV = (TextView)d.findViewById(android.R.id.message);
//TV.setLinkTextColor(Color.MAGENTA);
I looked at the AlertDialog documentation and it appears that when you call its method, it searches an XML that you've processed in its onStart method (http://developer.android.com/reference/android/app/Dialog.html#findViewById%28int%29). Instead, simply call your activity's findViewById method (e.g. if this is in an activity class, just calling:
TextView TV = (TextView) findViewById(android.R.id.message);
should work.)
If you are using a DialogFragment, it is accessible after DialogFragment.onStart() method as eluded to in the prior answer.
@Override
public void onStart() {
super.onStart();
final TextView textView = (TextView) getDialog().findViewById(android.R.id.message);
//Do something!
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With