Android:进度对话框大小

时间:2014-03-20 10:58:20

标签: android dialog size width progress

我创建了一个带有进度对话框的应用,用于打开新活动。默认值是文本的宽度。我可以做到总是占据屏幕的宽度。感谢

pDialog = new ProgressDialog(MainActivity.this, R.style.Theme_MyDialog);
pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pDialog.setMessage("DIALOG");
pDialog.setCancelable(true);
pDialog.setMax(100);

pDialog.setOnCancelListener(new OnCancelListener() {
    @Override
    public void onCancel(DialogInterface dialog) {
        ...
    }
});

pDialog.setOnShowListener(new OnShowListener() {
    @Override
    public void onShow(DialogInterface dialog) {
        ProgressBar v = (ProgressBar)pDialog.findViewById(android.R.id.progress);
        v.getIndeterminateDrawable().setColorFilter(Modulo.coloresListview
                (MainActivity.this, 
                perfilObj.getColor())[1],
                android.graphics.PorterDuff.Mode.MULTIPLY);

    }
});

pDialog.setProgress(0);
pDialog.show();

修改

MY CURRENT PROGRESS

MY WHISED PROGRESS

风格

<style name="Theme.MyDialog" parent="@android:style/Theme.Dialog">
    <item name="android:windowFrame">@null</item>
        <item name="android:windowBackground">@color/transparente</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">true</item>
        <item name="android:textColor">#FFFFFF</item>
        <item name="android:textSize">15sp</item>
    </style>

1 个答案:

答案 0 :(得分:0)

请访问@ joao2fast4u建议的链接How do I set an Android ProgressBar's Size programmatically?。 并在下面的代码中使用将在布局参数中设置的屏幕宽度。

显示display = getWindowManager()。getDefaultDisplay();         点大小=新点();

    try { 
        display.getRealSize(size);
        screenWidth = size.x;
        screenHeight = size.y; 
    } catch (NoSuchMethodError e) {
        screenWidth = display.getWidth();
        screenHeight = display.getHeight();
    }