以下是我的自定义进度条代码。我只有Gravity的问题。
这是代码。
dialog = new ProgressDialog(LandingPageActivity.this, R.style.AppBaseTheme);
dialog.setCancelable(false);
dialog.setIndeterminateDrawable(getResources().getDrawable(R.anim.progressbar));
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.getWindow().setGravity(Gravity.CENTER_HORIZONTAL);
dialog.show();
Style.xml
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
<item name="android:alertDialogStyle">@style/CustomAlertDialogStyle</item>
<item name="android:windowBackground">@color/transparent</item>
</style>
style name="CustomAlertDialogStyle">
<item name="android:bottomBright">@color/transparent</item>
<item name="android:bottomDark">@color/transparent</item>
<item name="android:bottomMedium">@color/transparent</item>
<item name="android:centerBright">@color/transparent</item>
<item name="android:centerDark">@color/transparent</item>
<item name="android:centerMedium">@color/transparent</item>
<item name="android:fullBright">@color/transparent</item>
<item name="android:fullDark">@color/transparent</item>
<item name="android:topBright">@color/transparent</item>
<item name="android:topDark">@color/transparent</item>
<item name="android:gravity">center</item>
</style>
动画文件代码
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/anim00" android:duration="150" />
<item android:drawable="@drawable/anim01" android:duration="150" />
<item android:drawable="@drawable/anim02" android:duration="150" />
<item android:drawable="@drawable/anim04" android:duration="150" />
</animation-list>
我可以正确显示进度条,但重力默认为左上角。
感谢您的帮助。
谢谢
答案 0 :(得分:3)
您需要在style.xml
文件中创建一个具有android:Theme.Holo.Dialog
主题的自定义样式。像,
<style name="CustomProgress" parent="android:Theme.Holo.Dialog">
<item name="android:alertDialogStyle">@style/CustomAlertDialogStyle</item>
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:textStyle">normal</item>
<item name="android:textSize">12sp</item>
</style>
并将CustomAlertDialogStyle
添加到CustomProgress
样式而不是AppBaseTheme
。
现在使用您的ProgressDialog
dialog = new ProgressDialog(LandingPageActivity.this, R.style.CustomProgress);
答案 1 :(得分:1)
在dialog.show()上面添加以下代码。希望它可以工作..
Window window = dialog.getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
wlp.gravity = Gravity.BOTTOM;
window.setAttributes(wlp);
dialog.show();