Change title font of Alert Dialog box

后端 未结 14 1924
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-16 10:57

I want to change the font of the title of Alert Dialog box.

Can anybody tell how can I do it?

相关标签:
14条回答
  • 2020-12-16 11:44

    Instead of setting the text of the alertdialog, you should set a custom view form your layouts. And before you do so, modify your view's font. try this example

    TextView content = new TextView(this);
         content.setText("on another font");
         content.setTypeface(Typeface.SANS_SERIF);
    

    //Use the first example, if your using a xml generated view

     AlertDialog.Builder myalert = new AlertDialog.Builder(this);
         myalert.setTitle("Your title");
         myalert.setView(content);
         myalert.setNeutralButton("Close dialog", null);
         myalert.setCancelable(true);
         myalert.show();
    

    code for xml...replace your font in the xml

    <TextView
        android:id="@+id/yourid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="8dp"
        android:text="your content" />
    
    0 讨论(0)
  • 2020-12-16 11:45

    Try setting theme for the dialog. Change the typeface attribute like this :

    <style name="CustomDialog" parent="android:Theme.Dialog">
        <item name="android:typeface">serif</item>
    </style>
    

    Though this changes Fonts of all the textviews within the dialog. so make sure TextViews are set to proper typeface

    0 讨论(0)
提交回复
热议问题