Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

android - Why the background of ProgressDialog doesn't set to the transparent?

I want to set the back ground to the transparent , so I have set the following code in

styles.xml
<style name="dialog" parent="@android:style/Theme.Dialog">  
            <item name="android:windowFrame">@null</item>  
            <item name="android:windowIsFloating">true</item>  
            <item name="android:windowContentOverlay">@null</item>  
            <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>  
            <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>  
            <item name="android:windowBackground">@android:color/transparent</item>  
            <item name="android:windowNoTitle">true</item> 
        </style> 

And I have use the Progressdialog like the following code in JAVA file and in fragment.

Activity activity = getActivity() ;
mProgressDialog = new ProgressDialog(activity,R.style.dialog) ;
mProgressDialog.setCancelable(false) ;
mProgressDialog.show() ;

But I get the progress like the following picture , and it doesn't has transparent background.

enter image description here

Why the background doesn't change to the transparent ?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

create custom MyTheme in valuesstyles.xml

<style name="MyTheme" parent="android:Theme.Holo.Dialog">
    <item name="android:alertDialogStyle">@style/CustomAlertDialogStyle</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:textColorPrimary">#FFFFFF</item>
     <item name="android:backgroundDimEnabled">false</item>
    <item name="android:textColor">#FFFFFF</item>
    <item name="android:textStyle">normal</item>
    <item name="android:textSize">12sp</item>
</style>

And also add this CustomAlertDialogStyle in valuesstyles.xml

 <style name="CustomAlertDialogStyle">
<item name="android:bottomBright">@android:color/transparent</item>
<item name="android:bottomDark">@android:color/transparent</item>
<item name="android:bottomMedium">@android:color/transparent</item>
<item name="android:centerBright">@android:color/transparent</item>
<item name="android:centerDark">@android:color/transparent</item>
<item name="android:centerMedium">@android:color/transparent</item>
<item name="android:fullBright">@android:color/transparent</item>
<item name="android:fullDark">@android:color/transparent</item>
<item name="android:topBright">@android:color/transparent</item>
<item name="android:topDark">@android:color/transparent</item>
</style>

And set ProgressDialog like:

 pd = new ProgressDialog(getActivity(),R.style.MyTheme);
 pd.setCancelable(false);
 pd.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
 pd.show();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...