Lottie 与 DialogFragment 背景问题

Lottie with DialogFragment background problem

我正在使用 Lottie 库为我的应用程序添加一些动画。我正在使用 DialogFragment 测试一个简单的加载示例,但是对话框的背景颜色是白色,我需要该颜色不可见。

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();
}
}

布局:

<?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>

那是我的背景颜色:

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

谢谢!

我修复了 onActivityCreated 代码的问题。

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);
}
}

在 XML 中将 Lottie 动画视图设置为特定大小,例如 100dp x 100dp。将可见性设置为 ="gone"。如果您希望加载动画显示在点击或某些进度菜单上,则将可见性设置为 VISIBLE,当进度达到 = 100 时,在 java 文件中设置可见性 INVISIBLE。