-1

I am trying to create a dialog like this but only with three clickable colored Buttons

enter image description here

When you click on a color the dialog goes away and the choosen button appears on the main screen

I currently have only three xml files for the different buttons and I don't know how to continue.

I'm thinking of creating a single choice list dialog, but I'm not sure if it is possible to show the three buttons horizontally and instead of a text to show the buttons.

Could somebody please help me?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Cicciopasticcio
  • 195
  • 1
  • 2
  • 8
  • You could use 3 TextViews, with a circular Shape inside. Since TextViews respond to clicks, you're pretty much done! – Phantômaxx Jan 16 '20 at 17:07

1 Answers1

0

I'm thinking of creating a single choice list dialog, but I'm not sure if it is possible to show the three buttons horizontally and instead of a text to show the buttons.

It's not possible, and the implementation could vary among OS versions or manufacturers anyway.

You will want to create your own xml layout and create a custom DialogFragment that inflates your xml layout in DialogFragment.onCreateView().

dialog_color_button_picker.xml

<LinearLayout>
    ... however you want to do your layout ...
</LinearLayout>

ColorButtonPickerDialog.kt

class ColorButtonPickerDialog: DialogFragment() {
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val rootView = inflater.inflate(R.layout.dialog_color_button_picker, container, false)
    }
}

Within ColorButtonPickerDialog.onCreateView() you can then reference your views by id and add listeners just like you would with a normal fragment.

Matt Robertson
  • 2,928
  • 5
  • 34
  • 62