Friday, July 13, 2018

How to set custom font for alert dialog in android?



In my android application an alert dialog appears after clicking on a button. I want to set custom font for the alert. I searched the web and found some tutorials and questions about this subject, but none of them works for me.



How can I change the font?



Thanks


Answer




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/FONT");
textView.setTypeface(face);

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...