Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize title in DialogFragment

I want to customize my title in my DialogFragment, I know how to How to set the title to my DialogFragment , but I want more not just a title , I need a customized title(color,fontSize ...), So I defined a TextView and customized it

public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.height_fragment,container,false);

    TextView title =  new TextView(getContext());
    title.setText("Your Height Information");
    title.setGravity(Gravity.CENTER);
    title.setTextSize(30);
    title.setBackgroundColor(Color.GRAY);
    title.setTextColor(Color.WHITE);

    getDialog().setCustomTitle(title); //Error Can not resolve method setCustomTitle(android.widget.TextView)

    return view;
}

but there is an error on this line

getDialog().setCustomTitle(title);

getDialog().setCustomTitle(title);

I searched a lot before posting this question but I couldn't find how can I customize my title of DialogFragment. Thank you for taking time to help me

like image 758
S S abbasi Avatar asked Nov 30 '25 04:11

S S abbasi


1 Answers

"getDialog" does not have a method "setCustomTitle".This method can only be used for AlertDialog.Builder. Try it like this:

getDialog().setTitle("Your Height Information");
TextView textView=(TextView) getDialog().findViewById(android.R.id.title);
textView.setTextSize(30);
like image 86
Дианка Best Avatar answered Dec 02 '25 18:12

Дианка Best



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!