0

我正在实施进度对话框自定义。在此我添加样式和颜色。

 <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);

我得到了背景颜色,但在进度对话框的顶部,我得到了黑色。 在此处输入图像描述

我提到了这个链接

我需要总背景颜色为深红色。

4

3 回答 3

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>

添加背景属性。这对我来说很好。 @颜色/黄色

于 2014-05-28T08:11:02.637 回答
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>

于 2013-12-11T09:19:26.467 回答
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()
于 2020-01-20T20:49:26.137 回答