如何在 Android 4.0 中使用来自 Android 5+ 的 ProgressBar

How to use ProgressBar from Android 5+ in Android 4.0

我正在使用 AppCompat 和设计库为 Android 4.0+ 开发应用程序。在 Android 5.0 上一切看起来都很好。但是在 Android 4.0 上我看到了旧的进度条样式。

Android 5.0

Android 4.0

Xml布局:

<FrameLayout 
    android:background="@color/colorPrimary"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <SeekBar
        android:id="@+id/play_seek_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</FrameLayout>

样式:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    </style>

    <style name="ActionBarTheme" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
        <item name="colorControlActivated">#fff</item>
    </style>
</resources>

Activity声明:

<activity android:name=".ui.PlayListsActivity"
    android:launchMode= "singleInstance"
    android:screenOrientation="portrait"
    android:theme="@style/AppBaseTheme"
    android:label="@string/app_name">

    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>

</activity>

我猜 AppCompat 只是为了 Holo。但是 5.0 是 Material

您可以像 EditText.But 一样获得小部件,但无法获得进度。

v7 appcompat 库的版本 23.1.0 添加了 material 设计 Seekbar 正如您在 changelog.

中看到的

您可能正在使用旧版本的 v7 appcompat 库。更新到最新版本,SeekBar 将像其他小部件一样自动以 material 设计风格为主题。

更改应用程序的依赖项build.gradle:

dependencies {
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.android.support:design:23.1.0'

    ...
}

这些是在 Android 4.4.

上获得的结果

使用 v7 appcompat 库 v23.0.1:

使用 v7 appcompat 库 v23.1.0: