私はいくつかのテストを行いましたが、これを達成するための最良の方法はカスタムを行うことだと感じていますDialog
.
これが私がしたことの例です。これにより、質問 2 の回答が得られますが、質問 1 の修正方法がわかります。
public class MyProgressDialog extends Dialog {
public static MyProgressDialog show(Context context, CharSequence title,
CharSequence message) {
return show(context, title, message, false);
}
public static MyProgressDialog show(Context context, CharSequence title,
CharSequence message, boolean indeterminate) {
return show(context, title, message, indeterminate, false, null);
}
public static MyProgressDialog show(Context context, CharSequence title,
CharSequence message, boolean indeterminate, boolean cancelable) {
return show(context, title, message, indeterminate, cancelable, null);
}
public static MyProgressDialog show(Context context, CharSequence title,
CharSequence message, boolean indeterminate,
boolean cancelable, OnCancelListener cancelListener) {
MyProgressDialog dialog = new MyProgressDialog(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), new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
dialog.show();
return dialog;
}
public MyProgressDialog(Context context) {
super(context, R.style.NewDialog);
}
}
すべての静的メソッドはこのリンクから取得されますが、奇妙なことは何もありませんが、魔法はコンストラクターで発生します。パラメータとしてスタイルを渡すことを確認してください。そのスタイルは次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="NewDialog" parent="@android:Theme.Dialog">
<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>
</resources>
この結果ProgressBar
、画面の中央で回転します。箱なしbackgroundDim
となし。Dialog