Android fragment show as dialogfragment or usual fragment

前端 未结 3 1500
夕颜
夕颜 2020-12-30 06:10

What I am trying to achieve is to have a fragment that on tablet it shows as a DialogFragment, while on smartphone it would be shown as a regular fragment. I am

3条回答
  •  再見小時候
    2020-12-30 06:42

    OK, I have been there and done that. To make a DialogFragment you need a layout defined in XML. Say, for this you have LinearLayout as root. In this LinearLayout you can add a fragment class="...." and when you display your DialogFragment, it will be the same Fragment you displayed side by side on the tablet now displayed in a DialogFragment.

    
    
      
    

    Like so. And inflate this in your DialogFragment

提交回复
热议问题