удаление фона из диалогового окна прогресса - PullRequest
0 голосов
/ 13 апреля 2019

Я использую пользовательский диалог прогресса в моем приложении.Это показано на фото ниже. Я хочу отредактировать две вещи. Сначала удалите черный фон, который появляется за кругом. Во-вторых, увеличьте громкость круга и измените его цвет.

enter image description here

Это стиль

<style name="CustomDialog" parent="@android:style/Theme.Dialog">
        <item name="android:textColor">#FF4081</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:background">@android:color/transparent</item>
        <item name="android:windowFrame">@android:color/transparent</item>
    </style>

Это мой код

dialog = new ProgressDialog(activity.this,R.style.CustomDialog);
            dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
            dialog.show();

Ответы [ 3 ]

1 голос
/ 13 апреля 2019

ProgressDialog устарела. Вы можете создать свой собственный диалог прогресса, используя диалоговое окно оповещения.

public static AlertDialog showProgressBar(Context context){
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    @SuppressLint("InflateParams") View view = inflater.inflate(R.layout.layout_custom_progress_bar, null);
    builder.setView(view);
    AlertDialog dialog = builder.create();
    dialog.show();
    return dialog;
}

Затем вы можете создать диалоговое окно, чтобы вы могли вручную закрыть его. Используйте это так.

AlertDialog dialog = showProgressBa(this); // this will automatically show the custom progress bar
// to dismiss
dialog.dismiss();

Вот ваш пользовательский макет для диалога прогресса.

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

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="20dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <ProgressBar
        android:id="@+id/progress_bar"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_marginStart="16dp"
        android:indeterminateDrawable="@drawable/progress_bar"
        android:max="100"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

Ваш индикатор прогресса можно нарисовать. Вы можете изменить цвет, изменив значения android:centerColor android:endColor android:startColor

// progress_bar
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="1080" >

<shape
android:innerRadius="18dp"
android:shape="ring"
android:thickness="4dp"
android:useLevel="false" >

<size
    android:height="48dp"
    android:width="48dp" />

<gradient
    android:centerColor="@color/colorPrimary"
    android:centerY="0.5"
    android:endColor="@color/colorWhite"
    android:startColor="@color/colorPrimary"
    android:type="sweep"
    android:useLevel="false" />

</shape>
</rotate>
0 голосов
/ 13 апреля 2019

Вы можете использовать макет обновления смахивания для этой функции вместо удаления фона из диалогового окна.

Вы можете реализовать его в java, не добавляя его в макет xml.

public class Test extends AppCompatActivity{

     SwipeRefrehLayout swipeRefresh;

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

        swipeRefresh = new SwipeRefreshLayout();
        swipeRefresh.setEnabled(true)

        //Set Colour Scheme
        swipeRefreshLayout.setColorSchemeResources(#FF6F00, #880E4F, #000000);

        showSwipeRefresh(true);
    }

    private void showSwipeRefresh(boolean show){

        if (show){
            swipeRefresh.setRefreshing(true);
        } else {
            swipeRefresh.setRefreshing(false);
        }
    }
}
0 голосов
/ 13 апреля 2019

Попробуйте это.

dialog= new Dialog(mContext);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.custom_progress_layout);
dialog.findViewById(R.id.progress_bar).setVisibility(View.VISIBLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);
dialog.show();
...