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

时间:2015-11-08 14:20:51

标签: android user-interface layout android-appcompat

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

Android 5.0
enter image description here

Android 4.0
enter image description here

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 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>

2 个答案:

答案 0 :(得分:2)

v7 appcompat库的23.1.0版添加了材料设计Seekbar,您可以在changelog中看到。

您可能正在使用旧版本的v7 appcompat库。更新到上一个版本,SeekBar将自动以其他小部件的材料设计样式为主题。

更改应用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:
enter image description here

使用v7 appcompat库v23.1.0:
enter image description here

答案 1 :(得分:0)

我猜AppCompat只适用于Holo。但5.0是Materialenter image description here

你可以像EditText一样获得Widget。但是你无法获得进步。