4

I'm working on an Android TV project which is a leanback project basically.

I want to show an alert dialog similar to the permission dialog in android tv apps. see the image.

permission dialog in android tv app

I tried adding normal AlertDialog like this:

AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context);
alertBuilder.setCancelable(true);
alertBuilder.setTitle("Permission necessary");
alertBuilder.setMessage("External storage permission is necessary");
AlertDialog alert = alertBuilder.create();
alert.show();

but that doesn't help. Can anyone show me the way to show similar AlertDialog in Android TV app?

Keval Langalia
  • 1,762
  • 1
  • 16
  • 29

1 Answers1

1

I didn't find a solution and created a custom DialogFragment, Look at github

And now I can create the dialog I need like this

val dialogExit = LeanbackDialogFragment(R.string.dialog_exit, R.string.dialog_exit_d, R.drawable.ic_exit)
dialogExit.addButton(R.string.yes) { dialog, which ->
    exitProcess(0)
}
dialogExit.addButton(R.string.no)
dialogExit.addButton("I don't know")
dialogExit.show(requireActivity().supportFragmentManager)

Result

enter image description here

Tiarait
  • 175
  • 1
  • 12