Skip to content Skip to sidebar Skip to footer

Place A Button Inside Dialogfragment's Title

I show a DialogFragment from another DialogFragment. I need to set title and a button just next to it. I don't want to reimplement the theme and create a custom view inside DialogF

Solution 1:

Try something like this:

// TitlefinalinttitleId= getResources().getIdentifier("alertTitle","id","android");
TextViewtitle= (TextView) popup.findViewById(titleId);
title.setText("My new title");

// Title's parent layoutViewGroupviewGroup= (ViewGroup) title.getRootView();

// ButtonButtonbutton=newButton(this);
button.setText("A Button");
viewGroup.addView(button);

Note: You may need to adjust the button and title objects' LayoutParams.

Solution 2:

An update. This can be achieved by calling setCustomTitle on AlertDialog.Builder class. Available since api level 1, and do not require a bunch of code.

Example:

AlertDialog.Builder(getActivity()).setCustomTitle(getActivity().getLayoutInflater().inflate(R.layout.my_custom_view, viewGroup)).create()

Post a Comment for "Place A Button Inside Dialogfragment's Title"