Skip to content Skip to sidebar Skip to footer

Android Add Button To Fragment Without Id

I want to display a button in the left down corner of a fragment but I don't know the Id of the fragment's main layout as I am in an abstract class that has no layout. @EFragment(R

Solution 1:

You can use the Fragment's getView() method to get the root view containing all the Layout of the Fragment. As long at this is a ViewGroup you can add your Button using the addView() method.

However to place if correctly, you'd have some knowledge about the Layout used, e.g. RelativeLayout, LinearLayout etc.

A more hardcore solution would be to create your own RelativeLayout, add the result of Fragment's getView() and your own Button and set your RelativeLayout as the new Root View of the Fragment.

Post a Comment for "Android Add Button To Fragment Without Id"