Search code examples
androidlayoutbackground-colorlottie

Lottie with DialogFragment background problem


im using a Lottie Library to give some animation to my app. Im testing a simple loading example with a DialogFragment, but the background color of dialog is white and im need that color to be invisible.

Activity:

public class MainActivity extends AppCompatActivity implements MainActivityContract.View{

private ProgressDialog progressDialog;
private Button button;
private MainActivityContract.Presenter presenter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    button = findViewById(R.id.button);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {


        }
    });

    presenter = new MainActivityController(this);
    presenter.initInterface();
}

@Override
public void initProgressBar() {
    progressDialog = new ProgressDialog();
    progressDialog.show(getSupportFragmentManager(),"teste");
}

@Override
public void finishProgressBar() {
    progressDialog.dismiss();
}
}

Layout:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/invisible"
xmlns:app="http://schemas.android.com/apk/res-auto">

<com.airbnb.lottie.LottieAnimationView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:lottie_autoPlay="true"
    app:lottie_rawRes="@raw/glow_loading"
    app:lottie_loop="true"/>

</FrameLayout>

and that is my background color:

<color name="invisible">#00ffffff</color>

DialogFragment with a Lottie animation

Thx!


Solution

  • I fix the problem with onActivityCreated code.

    public class ProgressDialog extends DialogFragment {
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    
        View rootView = inflater.inflate(R.layout.progress_bar, container);
    
        return rootView;
    }
    
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        setStyle(DialogFragment.STYLE_NO_FRAME, android.R.style.Theme);
    }
    }