Preference Center for the Android SDK

Display Preference Centers using the Airship UI, which automatically handles user preferences and syncs with the Airship backend.

 Important

Airship Preference Centers are widgets that can be embedded in a page in an app or website. Please verify with your legal team that your full Preference Center page, including any web page for email Preference Centers, is compliant with local privacy regulations.

The Preference Center feature allows users to manage their subscription list preferences as configured in the Airship Dashboard. Airship provides two distinct modules for displaying Preference Centers on Android, depending on your app’s UI framework:

  • urbanairship-preference-center-compose: Provides Compose-based Preference Center UI components, for apps built with Jetpack Compose.
  • urbanairship-preference-center: Provides XML-based Preference Center UI components, for apps using traditional Android Views (XML layouts).

You should select only one module based on your UI framework—do not include both modules in the same app.

For more information about configuring Preference Centers, see the Preference Center user guide.

Installation

Include the correct module for your chosen UI framework:

App build.gradle.kts


dependencies {
    val airshipVersion = "androidSdkVersion"

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

dependencies {
    val airshipVersion = "androidSdkVersion"

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

Displaying a Preference Center

Display a Preference Center with a single method call. The Preference Center will be launched in its own Activity over your app, allowing users to manage their subscription preferences, and automatically syncing changes with Airship.

Display Preference Center

Airship.preferenceCenter.open("my-first-pref-center")
PreferenceCenter.shared().open("my-first-pref-center");
 Note

To embed the Preference Center directly in your app’s navigation instead of displaying it as an overlay, see Embedding the Preference Center. You can also intercept display requests to handle navigation to your embedded Preference Center.

Applying a Custom Theme

You can customize the appearance of the Preference Center to match your app’s style. Android supports theme customization through both Jetpack Compose and XML Views.

To apply a custom theme to the ready-to-use Preference Center UI, create a theme and set it on the PreferenceCenter instance early in your app’s lifecycle. The overridden onAirshipReady() method in your Autopilot class is a good place to do this.

Customizing the theme with Jetpack Compose
// Configure Preference Center Theme
val preferenceCenterTheme = PreferenceCenterTheme(
    lightColors = PreferenceCenterColors.lightDefaults(
        background = Color(0xDEDEDE),
        surface = Color(0xFFFFFF),
        accent = Color(0x6200EE),
    ),
    darkColors = PreferenceCenterColors.darkDefaults(
        background = Color(0x121212),
        surface = Color(0x1E1E1E),
        accent = Color(0xBB86FC),
    ),
    typography = PreferenceCenterTypography.defaults(
        fontFamily = FontFamily(context.resources.getFont(R.font.roboto_regular))
    )
)

// Apply theme to default Preference Center UI
Airship.preferenceCenter.theme = preferenceCenterTheme

The ready-to-use Preference Center UI uses the UrbanAirship.PreferenceCenter style. You can use xml resource merging to override the default styles, by defining the style in your app.

Extending from a Material3 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 Material3 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.