The latest release of android support library, 22.1, deprecates the ActionBarActivity
in favor of AppCompatActivity, which promises to bring a single consistent ActionBar for all devices starting with API Level 7 and above.
Also, the new update adds the ability to tint widgets automatically when using AppCompat, and adds support for consistent material design dialogs. Use support.v7.app.AlertDialog
(instead of android.app.AlertDialog
), to get nice looking material dialogs across multiple versions of devices.
Example:
1. In order to benefit from all these things, the first thing you should do is to update the support library to 22.1.0.
dependencies { // … compile 'com.android.support:appcompat-v7:22.1.0' }
AppCompatActivity
.
public class MainActivity extends AppCompatActivity { // ... }
AppCompat
or any descendants of it.
<application android:theme="@style/Theme.AppCompat">
Following the steps above will setup the application with the default theme, but the actionbar can be styled further by specifying the material color palette:
<style name="AppTheme" parent="Theme.AppCompat"> <item name="colorPrimary">@color/primary</item> <item name="colorPrimaryDark">@color/primaryDark</item> <item name="colorAccent">@color/accent</item> </style>
and then update your application theme to use AppTheme
.
<application android:theme="@style/AppTheme">
