'AlertDialog like permission dialog in Android TV (Leanback) App

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?



Solution 1:[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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tiarait