Search code examples
androidgoogle-play-servicesgoogle-places-apiandroid-theme

PlacePicker doesn't pick up material theme


I am using a PlacePicker library from Google Play Services which starts up a new activity. The new activity/picker has a toolbar (actionbar) which is not styled by default.

PlacePicker documentation states that

If you set custom colors in your application using the material theme, the place picker inherits the colorPrimary and colorPrimaryDark attributes from the theme.

I have a theme in my style.xml file:

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="colorPrimary">#5665bb</item>
    <item name="android:colorPrimary">#5665bb</item>
    <item name="colorPrimaryDark">#41456b</item>
    <item name="android:colorPrimaryDark">#41456b</item>
</style>

and I have set the theme to be used in my Android Manifesto file

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

The placepicker is created by the following code:

try {
    PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder();
    Intent intent = intentBuilder.build(Main.this);
    // Start the intent by requesting a result,
    // identified by a request code.
    startActivityForResult(intent, REQUEST_PLACE_PICKER);
} catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
    Log.e("", "Error with Google Play lib.");
}

However, the toolbar doesn't get styled. As before it has a white background and black text. It's interesting to note that my own toolbar (actionbar) does get styled.

How do I force the placepicker activity to adopt my theme?


Solution

  • This is an acknowledged issue by the development team.

    There is currently a known issue with setting custom theme colors on the PlacePicker. For now you can work around this by defining two colors with the names "primary" and "primary_dark" - these will be applied to the PlacePicker.

    Unfortunately setting the primary/primaryDark property on a theme will not affect the PlacePicker styling at the moment.

    EDIT: Seems to be fixed now.

    This should be fixed in Google Play Services 10.0. Place Picker and Autocomplete Widget will use the colorPrimary and colorPrimaryDark colors from your app.