Android进度对话重力问题

时间:2014-11-18 09:46:09

标签: android progressdialog customdialog

以下是我的自定义进度条代码。我只有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>

我可以正确显示进度条,但重力默认为左上角。

感谢您的帮助。

谢谢

2 个答案:

答案 0 :(得分:3)

解决方案:

您需要在style.xml文件中创建一个具有android:Theme.Holo.Dialog主题的自定义样式。像,

CustomProgress

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