我正在尝试显示带有自定义主题的进度栏.但是它在左上角而不是中心.如果我不使用自定义主题,它将以中心显示,但不是全屏显示,这会在背景中显示文本视图和其他元素,看起来很糟糕.以下是代码和屏幕截图
自定义主题:
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
在具有自定义主题的活动初始化进度对话框中:
progressBar = new ProgressDialog(context, R.layout.layout_progress_dialog);
progressBar.setMessage("Please wait...");
progressBar.setCancelable(false);
当我单独看到进度条主题的预览时,它正确显示如下.但是在活动中它显示错误的位置.
解决方法:
您正在需要主题ID的构造函数中传递布局的ID.
progressBar = new ProgressDialog(context, R.layout.layout_progress_dialog);
构造函数是
public ProgressDialog(Context context, int theme)
您应该在style.xml中定义自定义属性,并在此处传递该样式的ID.
标签:android-layout,android
来源: https://codeday.me/bug/20191111/2021438.html