问题
I am implementing the progress dialog customization. In this I am adding the styles and colors.
<style name="ProThemeOrange" parent="@android:style/Theme.Dialog">
<item name="android:alertDialogStyle">@style/CustomAlertDialogStyle</item>
<item name="android:textColorPrimary">#e6e6e6</item>
</style>
<style name="CustomAlertDialogStyle">
<item name="android:bottomDark">@color/yellow</item>
<item name="android:bottomMedium">@color/yellow</item>
<item name="android:centerBright">@color/yellow</item>
<item name="android:centerDark">@color/yellow</item>
<item name="android:centerMedium">@color/yellow</item>
<item name="android:fullBright">@color/yellow</item>
<item name="android:fullDark">@color/yellow</item>
<item name="android:topBright">@color/yellow</item>
<item name="android:topDark">@color/yellow</item>
</style>
And I am adding the style to ProgressDialog
.
ProgressDialog pd = new ProgressDialog(this, R.style.ProThemeOrange);
I am getting the background color but on the top of progress dialog I'm getting black Color.
I referred this link
I need total background color as crimsonred.
回答1:
<style name="ProThemeOrange" parent="@android:style/Theme.Dialog">
<item name="android:alertDialogStyle">@style/CustomAlertDialogStyle</item>
<item name="android:background">@color/yellow</item>
<item name="android:textColorPrimary">#e6e6e6</item>
</style>
Add the background properties. It's works fine to me. @color/yellow
回答2:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<RelativeLayout
android:layout_width="135dp"
android:layout_height="56dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="146dp"
android:background="#e64b3c"
android:orientation="horizontal" >
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/progressBar1"
android:text="Please wait..." />
</RelativeLayout>
回答3:
public class CustomProgressDialog {
private static CustomProgressDialog customProgressDialog = null;
private Dialog mDialog;
public static CustomProgressDialog getInstance(){
if (customProgressDialog == null){
customProgressDialog = new CustomProgressDialog();
}
return customProgressDialog;
}
public void ShowProgress(Context context, String message,boolean cancelable){
ProgressBar mProgressBar;
TextView textView;
mDialog = new Dialog(context);
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
mDialog.setContentView(R.layout.dialog_progressbar);
mProgressBar = mDialog.findViewById(R.id.progress_bar);
textView = mDialog.findViewById(R.id.progress_text);
textView.setText("" + message);
textView.setVisibility(View.VISIBLE);
mProgressBar.setVisibility(View.VISIBLE);
mProgressBar.setIndeterminate(true);
mDialog.setCancelable(cancelable);
mDialog.setCanceledOnTouchOutside(cancelable);
mDialog.show();
}
public void hideProgress(){
if (mDialog!=null){
mDialog.dismiss();
mDialog = null;
}
}
dialog_progressbar.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="24dp"
android:background="@drawable/dialog_background">
<TextView
android:id="@+id/progress_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:text="Your Message"
android:layout_marginEnd="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:textSize="16sp"
android:fontFamily="@font/iran_sans"
android:layout_centerInParent="true"
android:visibility="visible" />
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_alignParentStart="true"/>
</RelativeLayout>
using
CustomProgressDialog dialog = CustomProgressDialog.getInstance();
dialog.ShowProgress(this,"Your Message",true);
dialog.hide()
来源:https://stackoverflow.com/questions/19900017/how-to-customize-the-progress-dialog-in-android