0

我有一个代码要在最后显示文件内容时使用“Style.xml”。我想要做的是“ ProgressDailog Indicator 来改变它的颜色,这将在 Style.xml 中定义......简单。

公共类 SimpleProgressDialog 扩展对话框 {

public static SimpleProgressDialog show(Context context, CharSequence title,
        CharSequence message) {
    return show(context, title, message, false);
}

public static SimpleProgressDialog show(Context context, CharSequence title,
        CharSequence message, boolean indeterminate) {
    return show(context, title, message, indeterminate, false, null);
}

public static SimpleProgressDialog show(Context context, CharSequence title,
        CharSequence message, boolean indeterminate, boolean cancelable) {
    return show(context, title, message, indeterminate, cancelable, null);
}

public static SimpleProgressDialog show(Context context, CharSequence title,
        CharSequence message, boolean indeterminate,
        boolean cancelable, OnCancelListener cancelListener) {
    SimpleProgressDialog dialog = new SimpleProgressDialog(context);
    dialog.setTitle(title);
    dialog.setCancelable(cancelable);
    dialog.setOnCancelListener(cancelListener);
    /* The next line will add the ProgressBar to the dialog. */
    dialog.addContentView(new ProgressBar ( context , null ,android.R.attr.progressBarStyleLargeInverse ), new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    dialog.show();

    return dialog;
}

public SimpleProgressDialog(Context context) {
    super(context, R.style.NewDialog);
}   

}

这里是风格。我只想修改 style.xml

<?xml version="1.0" encoding="utf-8"?>

<resources>
  <!-- The style for the unit on the statistics activity. -->
<style name="NewDialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowTitleStyle">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:background">@android:color/transparent</item>
</style>

4

1 回答 1

1

您的要求并不完全清楚,但我强烈建议您将ProgressBar定义放在它自己的 XML 布局中。从那里,您可以通过添加属性轻松应用样式style="@style/NewDialog"

例如。创建progress.xml

<?xml version="1.0" encoding="utf-8"?>
<ProgressBar
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:id="@+id/progress"
  style="@style/NewDialog"
  >
</ProgressBar>

然后在您的代码中,执行以下操作:

dialog.setContentView(R.layout.progres);
于 2011-06-02T19:57:03.677 回答