Guest User

Untitled

a guest
Jan 16th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. fun Fragment.showDialog(fragment: DialogFragment, tag: String) {
  2. val ft = fragmentManager?.beginTransaction()
  3. val dialog = fragmentManager?.findFragmentByTag(tag) as? DialogFragment
  4. dialog?.let {
  5. ft?.remove(it)
  6. }
  7. dialog.
  8. ft?.addToBackStack(null)
  9. fragment.show(ft, tag)
  10. }
  11.  
  12. showDialog(SuccessDialog.newInstance(), SuccessDialog.TAG)
  13.  
  14. class SuccessDialog : DialogFragment() {
  15.  
  16. companion object {
  17. const val TAG = "SUCESS_DIALOG"
  18. fun newInstance() = SuccessDialog()
  19. }
  20.  
  21. override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
  22. savedInstanceState: Bundle?): View =
  23. inflater.inflate(R.layout.dialog_success, container, false)
  24.  
  25. override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
  26. super.onViewCreated(view, savedInstanceState)
  27.  
  28. dialog?.window?.setBackgroundDrawableResource(android.R.color.transparent)
  29. dialog?.window?.setDimAmount(0.8f)
  30.  
  31. closeButton.setOnClickListener {
  32. dialog.cancel()
  33. dialog.dismiss()
  34. }
  35.  
  36. }
  37. }
Add Comment
Please, Sign In to add comment