Is it possible to create a Button over a fragment activity?
I tried by dragging it on the screen but he doesn't allow me to do it Like that so, any alternative?
There's any way to do it from XML?
Asked
Active
Viewed 62 times
1

Chetan Joshi
- 5,582
- 4
- 30
- 43
-
try using custom dialog. – karan Feb 06 '19 at 06:25
-
Can you write just some Lines of an example code, I never used it, I'll appreciate it. – Feb 06 '19 at 06:32
-
https://stackoverflow.com/questions/13341560/how-to-create-a-custom-dialog-box-in-android check this – karan Feb 06 '19 at 06:33
-
This is not what I need to be honest, I need to create a Button not that – Feb 06 '19 at 06:40
1 Answers
0
You can use ViewStub for this: ViewStub is a View that is inflated lazily.
You can declare a ViewStub in an XML file like this:
<ViewStub android:id="@+id/stub"
android:inflatedId="@+id/subTree"
android:layout="@layout/mySubTree"
android:layout_width="120dip"
android:layout_height="40dip" />
The android:layout attribute is a reference to the View that will be inflated next to a call of inflate()
. So
ViewStub stub = (ViewStub) findViewById(R.id.stub);
View inflated = stub.inflate();
When the method inflate()
is invoked the ViewStub is removed from its parent and replaced with the right View (the root view of mySubTree layout).
If you want to do this pragmatically then your code should be something like:
ViewStub stub = new ViewStub(this);
stub.setLayoutResource(R.layout.mySubTree);
stub.inflate();
Here mySubtree is layout you want to show after inflating Activity
or Fragment
.

Chetan Joshi
- 5,582
- 4
- 30
- 43