我正在实现进度对话框自定义。在这里我添加了样式和颜色。
<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>
我正在将样式添加到ProgressDialog
。
ProgressDialog pd = new ProgressDialog(this, R.style.ProThemeOrange);
我正在获取背景颜色,但在进度对话框的顶部我得到了黑色。
我需要总背景颜色为深红色。
答案 0 :(得分:4)
<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>
添加背景属性。这对我来说很好。 的 @颜色/黄强>
答案 1 :(得分:0)
<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>
答案 2 :(得分:0)
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>
使用
CustomProgressDialog dialog = CustomProgressDialog.getInstance();
dialog.ShowProgress(this,"Your Message",true);
dialog.hide()