2016-04-15 87 views
1

我找不到理由不确定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 5 - API 22

的Nexus 5X,API 23

Nexus 5X - API 23

+0

AFAIK appcompat库永远不会改变ProgressDialog的ProgressBar风格......你必须建立自己的对话框... – Selvin

+0

你有不同的主题在不同的styles.xml? –

+0

所有版本只有一个主题。 – aguyngueran

回答

5

在样式补充一点:

<style name="MyAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog"> 
     <!-- Used for the buttons --> 
     <item name="colorAccent">@color/colorAccent</item> 
     <!-- Used for the title and text --> 
     <item name="android:textColorPrimary">@color/colorPrimaryDark</item> 
     <!-- Used for the background --> 
     <item name="android:background">@android:color/transparent</item> 
    </style> 

,并设置对话框:

ProgressDialog progressDialog = new ProgressDialog(MainActivity.this, R.style.MyAlertDialogStyle); 
+0

看起来像应用更改的进展,但仍然:对话框没有跨越整个宽度可用和Android 19更糟糕,你看到一些白色边框下的进展和黯淡的背景之上。 – aguyngueran

+0

@ android:color/transparent and @ android:color/transparent修复了边框。 – Yar