Android Preference Center Customization

Custom Android Preference Center guide.

Installation

Preference Center requires adding the urbanairship-preference-center module:


dependencies {
    val airshipVersion = "17.5.0"
    
    implementation("com.urbanairship.android:urbanairship-preference-center:$airshipVersion")
}

dependencies {
  def airshipVersion = "17.5.0"

  implementation "com.urbanairship.android:urbanairship-preference-center:$airshipVersion"
}

Styling the Android Preference Center

Extending from a MaterialComponents app theme
<!-- Use colors from MyAppTheme instead of the default pref center colors. -->
<style name="UrbanAirship.PreferenceCenter" parent="MyAppTheme">
  <!-- Specific attributes may also be overridden here, as needed. For example,
       the following overrides the background color used by PreferenceCenterFragment. -->
  <item name="android:colorBackground">@color/my_background_color</item>
</style>

If your app doesn’t use a MaterialComponents theme or you need the ability to further customize preference center styles, The Android resource merging feature can be used to override the default styles that the SDK provides. Copy the style sheet into the application’s resource directory, then change any of the styles.

Embedding the PreferenceCenterFragment

When embedding the PreferenceCenterFragment, either use a FragmentContainerView or create the fragment directly. You must specify the ID of the Preference center to be displayed when creating the fragment. The static create on PreferenceCenter will handle passing the given id to the fragment as an argument:

Instantiating a PreferenceCenterFragment

val fragment = PreferenceCenterFragment.create(preferenceCenterId = "my-first-pref-center")
PreferenceCenterFragment fragment = PreferenceCenterFragment.create("my-first-pref-center");

You will need to override the open behavior to navigate to the embedded fragment instead of letting Airship launch the PreferenceCenterActivity.