2016-02-05 32 views
0

我想定製ProgressDialog風格有類似的東西:風格爲Android ProgressDialog

enter image description here

我有什麼:

enter image description here

我知道如何更改微調風格和顏色,但我不明白的是:如何使圓角,我試圖使用android:radius屬性,但沒有任何變化,我不知道如何減少padding。也許我可以通過編程來實現它?

<style name="TransparentProgressDialog" parent="android:Theme.Holo.Dialog"> 
    <item name="android:alertDialogStyle">@style/CustomAlertDialogStyle</item> 
    <item name="android:windowBackground">@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">@dimen/_14sdp</item> 
</style> 

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

使用'Appcompat'主題? –

+0

@IntelliJAmiya yes – VLeonovs

+0

'parent =「android:style/Theme.Holo.Dialog」' –

回答

2

嘗試下面的代碼工作對我來說:

放入繪製此文件夾中的XML文件(dialog_progress_background.xml)

<corners android:radius="10dp" /> 

<solid android:color="#80000000" /> 

<padding 
    android:bottom="40dp" 
    android:left="40dp" 
    android:right="40dp" 
    android:top="40dp" /> 

Dailog佈局(R.layout.dialog_spinner.xml)

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <ProgressBar 
     android:id="@+id/progressBar" 
     style="?android:attr/progressBarStyleSmall" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" /> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/progressBar" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="20dp" 
     android:text="Loading..." 
     android:textColor="#FFFFFF" /> 

</RelativeLayout> 

//班創建自定義進度對話框

public class ProgressBuilder { 
    private Context context; 
    private Dialog dialog; 

    public ProgressBuilder(Context context) { 
     this.context = context; 

    } 

    public void showProgressDialog() { 
     dialog = new Dialog(context); 
     dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     dialog.getWindow().setBackgroundDrawable(
       context.getResources().getDrawable(
         R.drawable.dialog_progress_background)); 
     dialog.setContentView(R.layout.dialog_spinner); 
     dialog.setCancelable(false); 
     dialog.show(); 
    } 

    public TextView getTextView() 
    { 
     return (TextView)dialog.findViewById(R.id.textView1); 
    } 

    public Dialog getDialog() 
    { 
     return dialog; 
    } 

    public void dismissProgressDialog() { 
     dialog.dismiss(); 
    } 
} 

並調用showProgressDialog()方法來顯示進度對話框

ProgressBuilder dialog=new ProgressBuilder(MainActivity.this); 
    dialog.showProgressDialog() 

//駁回進度對話框

dialog.dismissProgressDialog() 
+0

請檢查[this](http://stackoverflow.com/questions/35223310/remove-white-background-from-progressdialog?noredirect=1#comment58160731_35223310) – VLeonovs