我找不到理由不确定ProgressDialog内显示进度条的风格Android的22和23之间是不同的的Android不确定的进度对话框进度条样式
让我们以一个非常简单的布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="example.com.progressbarcolor.MainActivity">
<Button
android:id="@+id/show_progress"
android:text="Show progres"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
<ProgressBar
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:indeterminate="true"
android:visibility="visible"/>
</RelativeLayout>
按下按钮显示ProgressDialog:
ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setIndeterminate(false);
progressDialog.setCancelable(false);
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();
应用的风格是:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
最后的gradle这个文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "example.com.progressbarcolor"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
}
正如你可以在图片下面看到里面直接布局时使用的应用程序都显示相同的进度条,但颜色内部ProgressDialog不同。
在Android 22上,进度对话框显示绿色进度条而不是红色进度条。
的Nexus 5,API 22
的Nexus 5X,API 23
AFAIK appcompat库永远不会改变ProgressDialog的ProgressBar风格......你必须建立自己的对话框... – Selvin
你有不同的主题在不同的styles.xml? –
所有版本只有一个主题。 – aguyngueran