使进度条背景透明

时间:2018-07-11 01:48:58

标签: android android-progressbar android-dialog

这是我得到的输出。

enter image description here

如您所见,进度条上有白色边框,我无法摆脱。我希望加载的内容包括米色球和其中的自定义动画。我为此使用了一个对话框。

下面是我的代码:

ActivityIndi​​cator扩展对话框。

public class ActivityIndicator extends Dialog {

    private ProgressBar progressBar;

    public ActivityIndicator(@NonNull Context context) {
        super(context);
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_indicator);
        this.setCancelable(false);

        progressBar = (ProgressBar) findViewById(R.id.progressBar);
        ThreeBounce threeBounce = new ThreeBounce();
        progressBar.setIndeterminateDrawable(threeBounce);
    }



}

ThreeBounce是我为动画导入的自定义库。

activityIndi​​cator.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">


<ProgressBar
    android:id="@+id/progressBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:background="@drawable/loading_ball>
</ProgressBar>


<com.github.ybq.android.spinkit.SpinKitView xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/spin_kit"
    style="@style/SpinKitView.ThreeBounce"
    android:layout_width="68dp"
    android:layout_height="59dp"
    android:layout_centerInParent="true"
    android:layout_gravity="center"
    android:background="@drawable/loading_ball"
    app:SpinKit_Color="@color/colorPrimary"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />


</RelativeLayout>

loading_ball.xml :(自定义圆圈图片视图)

 <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:drawable="@drawable/loadingball"/>
    <item android:drawable="@drawable/circle"/>

</layer-list>

circle.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:innerRadius="1.5dp"
    android:shape="ring"
    android:thicknessRatio="1.9"
    android:useLevel="false" >
    <solid android:color="@android:color/transparent" />

    <stroke
        android:width="0dp"
        android:color="@android:color/white" />
</shape>

我尝试将进度条背景设置为透明,但似乎不起作用。有什么办法可以做到这一点?

1 个答案:

答案 0 :(得分:0)

首先创建一个类加载器

public class Loader extends Dialog{

 public Loader(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
}

public Loader(Context context, int theme) {
    super(context, theme);
    // TODO Auto-generated constructor stub
    setContentView(R.layout.loader_layout);
}

public Loader(Context context, boolean cancelable,
              OnCancelListener cancelListener) {
    super(context, cancelable, cancelListener);
    // TODO Auto-generated constructor stub
}

}

是布局

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:background="#00ffffff">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00ffffff"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true">

    <com.github.ybq.android.spinkit.SpinKitView 
            xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/spin_kit"
        style="@style/SpinKitView.ThreeBounce"
        android:layout_width="68dp"
        android:layout_height="59dp"
        android:layout_centerInParent="true"
        android:layout_gravity="center"
        android:background="@drawable/loading_ball"
        app:SpinKit_Color="@color/colorPrimary"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</RelativeLayout>

并通过此方法调用加载程序

 Loader loader = new Loader(this,android.R.style.Theme_Translucent_NoTitleBar);
loader.show();
loader.setCancelable(false);
loader.setCanceledOnTouchOutside(false);