Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
530 views
in Technique[技术] by (71.8m points)

java - custom alert dialog background color

i need a custom alert dialog for show progress. when i run it the alert dialog background color not change to transparent... below i put my code in xml layout and alert dialog code

xml layout :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:background="@android:color/transparent"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">

<androidx.cardview.widget.CardView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:cardElevation="10dp"
    app:cardCornerRadius="100dp">

        <ProgressBar
            android:id="@+id/progressBar"
            style="@style/Widget.AppCompat.ProgressBar"
            android:layout_width="30dp"
            android:layout_margin="5dp"
            android:layout_height="30dp" />

</androidx.cardview.widget.CardView>

and this is my code in fragment :

                View progress = getLayoutInflater().inflate(R.layout.progress_alert, null);
            AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
            builder.setCancelable(false);
            builder.setView(progress);
            alertDialog = builder.create();
            alertDialog.show();
question from:https://stackoverflow.com/questions/65879469/custom-alert-dialog-background-color

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

try to set dialog theme like this in styles.xml

<style name="dialogTheme" parent="android:Theme.Holo.Dialog">
    <item name="android:windowMinWidthMajor">90%</item>
    <item name="android:windowMinWidthMinor">90%</item>
</style>

java code

Dialog dialog = new Dialog(activity, R.style.dialogTheme);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.your_dialog_layout);
activity.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);

dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...