/*
** if you use in mainactivity use:
* return this.getWindow().getDecorView().findViewById(android.R.id.content);
*
*/
final Button mybtn = new Button(this);
mybtn.setText("Your Button");
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.WRAP_CONTENT, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT);
#Add
((ViewGroup) getActivityContentView()).addView(mybtn, layoutParams);
#Remove
((ViewGroup) getActivityContentView()).removeView(mybtn);
}
public View getActivityContentView() {
try {
return ((Activity) getContext()).getWindow().getDecorView().findViewById(android.R.id.content);
} catch(ClassCastException e) {
throw new ClassCastException("Please provide an Activity context for this FloatingActionButton.");
}
}{