3

I have alertDialog with items,

this is the code:

  final CharSequence[] options = { "Back","continue"};
              AlertDialog.Builder builder = new  AlertDialog.Builder(myActivity.this);
              builder.setTitle(customTitle);

                builder.setItems(options, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int item) {
                        if (options[item].equals("Back"))
                        {

                            //do something;


                        }
                        else if (options[item].equals("continue"))
                        {
                           dialog.dismiss();
                        }

                    }
                });
                builder.show();

I have custom font in my assets folder, how can I connect the item's font to this font? I saw many answers but there is no answer for itmes in dialog, all answers was about the title or text uses by textView, I need to change the font of my items, someone can help me?

  • 1
    I looked on the same questions but didn't finde answer to my specific question, can someone that did the same help me? – user5912232 Feb 11 '16 at 13:22

1 Answers1

-2

To do this you use alert builder to build your alert. You then get the TextView from this alert and then you set the typeface for the alert.

AlertDialog dialog = new AlertDialog.Builder(this).setMessage("Hello world").show();
TextView textView = (TextView) dialog.findViewById(android.R.id.message);
Typeface face=Typeface.createFromAsset(getAssets(),"fonts/yourfont.ttf"); 
textView.setTypeface(face);
Kristo
  • 1,339
  • 12
  • 22
  • I tried this way but the app crashed, this way is change the font to the items also? where in the code I need to add this lines? maybe I didn't put them at the correct line? – user5912232 Feb 11 '16 at 11:45
  • You have to add the code in your `onCreate` method. plus you need to add the font file in your assets. If your api is <20 and you have your font file in your assets the it should work. It changed only the font of the dialog. – Kristo Feb 11 '16 at 11:53
  • take a look at this post if you cant make it. http://code.tutsplus.com/tutorials/customize-android-fonts--mobile-1601/ Good Luck. – Kristo Feb 11 '16 at 11:54
  • what this line mean? AlertDialog dialog = new AlertDialog.Builder(this).setMessage("Hello world").show(); where i need to place my alertDialog? – user5912232 Feb 11 '16 at 11:58
  • the link is talks about textViews, what about alertDialog items? I don't understand your answer... – user5912232 Feb 11 '16 at 12:17