Change title font of Alert Dialog box

后端 未结 14 1954
佛祖请我去吃肉
佛祖请我去吃肉 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:38

    TextView tv_message = new TextView(this);
    
                    Typeface typeface = Typeface.createFromAsset(
                            getAssets(),
                            "fonts/OpenSans-Semibold.ttf"
                    );
    
    
                    // Set the text view layout parameters
                    tv_message.setLayoutParams(
                            new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
                    );
    
                    // Set message text color
                    tv_message.setTextColor(Color.RED);
    
                    // Set message gravity/text align
                    tv_message.setGravity(Gravity.START);
    
                    // Set message text size
                    tv_message.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    
                    // Set message custom font
                    tv_message.setTypeface(typeface);
    
                    // Set message background color
                    tv_message.setBackgroundColor(Color.YELLOW);
    
                    // Set message text padding
                    tv_message.setPadding(15, 25, 15, 15);
    
                    tv_message.setText("Are you sure?");
                    tv_message.setTextColor(Color.BLACK);
    

提交回复
热议问题