可绘制着色:不确定ProgressBar

时间:2016-05-03 07:28:14

标签: android android-viewpager android-5.0-lollipop android-drawable android-5.1.1-lollipop

我一直试图为支持API 15的应用程序着色ProgressBar drawable。我也需要动态地执行它。这是我到目前为止所尝试的内容:

XML:

<ProgressBar
    android:id="@+id/progressBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:indeterminate="true" />

爪哇:

    Drawable drawable = DrawableCompat.wrap(progressBarSync.getIndeterminateDrawable());
    DrawableCompat.setTint(drawable, colorVibrantDark);

输出:

Android 6:

enter image description here

Android 4.4:

enter image description here

Android 5.0.1,5.1,5.1.1:

enter image description here

问题:

  • Android 5 :在运行Lollipop的设备上看不到ProgressBar。 (它可能是白色的,在白色背景上看不到!没有看到它根本不可见。)
  • Android 4.0-4.4 :此代码在ViewPager中运行。因此,更改页面会改变drawable的色调。

我还尝试了什么? (当事情不按预期工作时,开发人员有时会发疯!:))

    // wrap using DrawableCompat
    Drawable drawable = DrawableCompat.wrap(progressBarSync.getIndeterminateDrawable());
    // don't wrap using DrawableCompat :/
    Drawable indeterminateDrawable = progressBarSync.getIndeterminateDrawable();
    // set the tint for wrapped drawable
    DrawableCompat.setTint(drawable, colorVibrantDark);
    // change the color filter as well for the wrapped drawable
    drawable.setColorFilter(colorVibrantDark,
            PorterDuff.Mode.SRC_IN);
    // set the tint for the NOT wrapped drawable
    DrawableCompat.setTint(indeterminateDrawable, colorVibrantDark);
    // change the color filter as well for the NOT wrapped drawable        
    indeterminateDrawable.setColorFilter(colorVibrantDark,
            PorterDuff.Mode.SRC_IN);

感谢任何帮助/建议。

由于

0 个答案:

没有答案