0

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!

Flávio Costa
  • 895
  • 5
  • 18
  • 41

2 Answers2

1

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);
}
}
Flávio Costa
  • 895
  • 5
  • 18
  • 41
0

Set Lottie animation view to particular size say 100dp by 100dp in XML. Set visibility as ="gone". If you want loading animation to show up on click or some progress menu then set visibility as VISIBLE and when progress reaches = 100, set visibility INVISIBLE in java file.

Rajbir Shienh
  • 2,965
  • 1
  • 14
  • 21