Fragment upon fragment

40 Views Asked by At

I want add fragment B upon to fragment A. How can I do it?

This is my first fragment:

enter image description here

This is my 2nd fragment on top of the 1st fragment with transparent:

enter image description here

How can I write it with code? Plas write codes with fragment, not with activity

1

There are 1 best solutions below

0
AshKay On

You can just simply add the second fragment(B) on top of existing fragment

supportFragmentManager
   .beginTransaction()
   .add(R.id.fragmentContainer, SecondFragment())
   .commit()

by default fragment B will transparent if no background is set, you can set it's background to some translucent color by adding following line in fragment's root container

android:background="#66FFFFFF"

color is in #AARRGGBB format, you can adjust the transparency by changing the 66 field