Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

374
Vistas
How to access AlertDialog's Message and Title in Unity Android Plugin Library? (I am using custom Font in AlertDialog)

I want to use custom font in my android plugin library while using AlertDialog. Now here is the code to display AlertDialog using custom font.

AlertDialog alertDialog = new AlertDialog.Builder(mainActivity).setTitle("Title").setMessage("Message Text").create();
alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Cancel", dialogOnClickListener);

TextView alertMessageTextView = (TextView) alertDialog.findViewById(R.id.message); // I am getting error here
TextView alertTitleTextView = (TextView) alertDialog.findViewById(android.R.id.title); // I am getting error here

Typeface customFont = Typeface.createFromAsset(mainActivity.getResources().getAssets(), "fonts/lobster-regular.ttf");

alertMessageTextView.setTypeface(customFont);
alertTitleTextView.setTypeface(customFont);

alertDialog.show();

I am getting error:

Error Unity AndroidJavaException: java.lang.NoSuchFieldError: No static field message of type I in class Lcom/cptech/pluginexample/R$id; or its superclasses (declaration of 'com.cptech.pluginexample.R$id' appears in base.apk)

I have placed my font file in Unity's "Assets/Resources" Folder. Hence in final apk the font resources appear in "assets/fonts" folder. But however, this doesn't matter as, I can use custom font in other TextView(s).

The only problem is that it cannot find AlertDialog's message and title, as I believe. Any help would be appreciated.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Few changes:

Use show() instead of create() when building the AlertDialog:

AlertDialog alertDialog = new AlertDialog.Builder(mainActivity).setTitle("Title").setMessage("Message Text").show();

Then, replace this line:

TextView messageTextView = (TextView) alertDialog.findViewById(R.id.message);

With android.R.id.message instead, like so:

TextView messageTextView = (TextView) alertDialog.findViewById(android.R.id.message);

And make sure you're not accidentally doing import com.android.R at the top of your file. You need this change because the id message is not an asset in your module, it's a default asset from an android library. So the R you're using right now is coming from your package - you need to specify R from android.R.

Last thing quick, watch out for the variable name of the textview when you set the text, should be changed to messageTextView

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda