Places SDK for Android: styling an Autocomplete Activity

Viewed 1435

I am using an Intent to launch an Autocomplete Activity from the Places SDK for Android, as described here, along the following lines:

Intent intent = new Autocomplete.IntentBuilder(
        AutocompleteActivityMode.FULLSCREEN, fields)
        .build(this);
startActivityForResult(intent, AUTOCOMPLETE_REQUEST_CODE);

But I cannot see a way of styling the resulting Autocomplete Activity, to make it match the theme of my app as closely as possible, and in particular to follow the day/night theme being used in the app. At present the background of the places list always appears to be white, with dark text on top, i.e. suited only to a light theme.

For example the following is what it looks like, when launched from within an app running on a system set to dark theme:

enter image description here

How is this Activity meant to be styled?

2 Answers

In colors.xml file make sure you have these defined:

<resources>
   <color name="colorPrimary">#ffffff</color>
   <color name="colorPrimaryDark">#03DAC5</color>
   <color name="colorAccent">#03d</color>
</resources>

In styles.xml you should have this defined:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
   <item name="colorPrimary">@color/colorPrimary</item>
   <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
   <item name="colorAccent">@color/colorAccent</item>
</style>

With that I was able to change the colors of the Places SDK.

colorPrimary is used for the background surrounding the EditText

colorPrimaryDark is used for the status bar

Styles & Screenshot

According to the documentation there is something called AutoCompleteActivity that extends AppCompatActivity as well as AutocompleteSupportFragment that extends Fragment.

instead of using the IntentBuilder to create what i assume is just a generic version of AutocompleteActivity you should create your own AutocompleteActivity using the provided constructor and then override onCreate to set the Theme to dark. and then you just open the activity like you would with a regular intent.

Important note: in the documentation you will find that for some reason AutocompleteSupportFragment includes a lot more usefull methods that could be interesting for you (like setLocationRestriction(), setPlaceFields(), setTypeFilter etc) but for some reason these dont appear in the docs of AutoCompleteActivity. im not sure if they just forgot to put them in the doc or if the fragment version is actually more powerful than the Activity. this just means you might have to use the fragment (and plant it into an empty activity) instead of the activity.

Related