我正在尝试将ProgressDialog放在Activity的中心。
这是我的ProgressDialog:
final ProgressDialog pd = new ProgressDialog(ActivityLoginRegistration.this, R.style.ProgressDialogStyle);
pd.setMessage(getString(R.string.Loading_message_alert));
pd.setCancelable(false);
pd.show();
这是我的风格资源:
<style name="ProgressDialogStyle">
<item name="android:layout_gravity">center</item>
<item name="colorAccent">#A5865F</item>
</style>
但pd显示为 this
我尝试过使用pd.getWindow().setGravity(Gravity.CENTER);
但它不适用于我。
如何将ProgressDialog放在我的Activity的中心?
答案 0 :(得分:0)
尝试将“进度对话框”重力的整个内容更改为居中对话框可能居中,但宽度可能为match parent
,因此内容不在中心位置:
同时添加以下行:
<item name="android:gravity">center</item>
最终样式如下:
<style name="ProgressDialogStyle">
<item name="android:layout_gravity">center</item>
<item name="android:gravity">center</item>
<item name="colorAccent">#A5865F</item>
</style>
答案 1 :(得分:0)
我解决了这个问题。
要更改progressBar颜色,我会覆盖整个条形资源,而不仅仅是它的样式。
progressbar_handler.xml:
ProgressDialog pd = new ProgressDialog(ActivityLoginRegistration.this);
pd.setMessage(getString(R.string.Loading_message_alert));
pd.setCancelable(false);
pd.show();
pd.setIndeterminate(true);
pd.setIndeterminateDrawable(getResources().getDrawable(R.drawable.progressbar_handler));
然后我将它应用到我的ProgressDialog:
NotificationCenter.default.post(name: Notification.Name("buttonAIsPressed"), object: nil)
所以结果如下:image