Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

372
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!