Android SharedPreferences Tutorial and Example

Practical tooltips and info bubbles for Android guidance

Android apps often need to explain a control without interrupting the task already in progress. A tooltip can name an unfamiliar icon, while an info bubble can offer a short explanation, an example, or a single action beside the relevant view.

Both patterns work best when they are contextual, readable, and easy to dismiss. This guide covers Android Material components, safe lifecycle handling, and practical testing for Australian users.

Choosing the right guidance pattern

Use a tooltip for a compact label attached to an icon or control that might not be immediately understood. It acts as a brief hint and should not contain instructions that require careful reading or multiple steps.

An info bubble, also called a callout, is better for contextual help. It can sit beside a form field, explain a restricted feature, provide an example, or offer a relevant next action.

Choose according to the complexity of the message. Snackbar messages suit brief status updates, inline text suits persistent instructions, and a dialog should be reserved for a decision that blocks the current task.

Adding a Material tooltip

Add the Material dependency to the app module before using the tooltip APIs:

implementation("com.google.android.material:material:1.12.0")

A MaterialButton can receive its tooltip text at runtime. This approach works with strings stored in Android resources and avoids duplicating accessibility text in the layout:

val saveButton = findViewById<MaterialButton>(R.id.save_button)

TooltipCompat.setTooltipText(
    saveButton,
    getString(R.string.save_tooltip)
)

Material supplies long-press behaviour on touch devices and hover behaviour on pointer-based devices. Keep the wording short, such as “Save changes”, and use contentDescription when the button itself contains only an image.

TalkBack may announce tooltip text, but it should never be the only accessible label for a control. Test the reading order so the button name, state, and extended guidance remain clear without forcing users through repeated prompts.

Creating an anchored info bubble

An info bubble needs an anchor, a compact layout, and a dismissal path. A rounded background, generous padding, and an optional arrow make the relationship with the anchor clear.

Create a small layout containing the bubble text:

<TextView
    android:id="@+id/bubble_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/bg_info_bubble"
    android:padding="16dp" />

Load that layout into a PopupWindow and position it below the triggering view:

private fun showInfoBubble(anchor: View) {
    val bubbleView = layoutInflater.inflate(
        R.layout.view_info_bubble,
        null
    )

    val popup = PopupWindow(
        bubbleView,
        ViewGroup.LayoutParams.WRAP_CONTENT,
        ViewGroup.LayoutParams.WRAP_CONTENT,
        true
    ).apply {
        elevation = 12f
        isOutsideTouchable = true
    }

    bubbleView.findViewById<TextView>(R.id.bubble_text).text =
        getString(R.string.info_bubble_text)

    guidancePopup = popup
    popup.showAsDropDown(anchor)
}

Anchor the bubble to the relevant control and confirm that it remains within the display boundaries. If space is tight, reposition it above or beside the anchor instead of allowing important text to fall off the screen.

Adding actions and managing state

If the bubble includes a button, handle the action from the same listener and dismiss the overlay before moving to the next screen. This prevents a stale popup from remaining visible over new content.

bubbleView.findViewById<View>(R.id.bubble_action).setOnClickListener {
    popup.dismiss()
    onGuidanceConfirmed()
}

Keep a reference to the popup so it can be dismissed when the host activity stops. A PopupWindow holds a reference to its context, so leaving it attached across lifecycle changes can cause memory leaks.

private var guidancePopup: PopupWindow? = null

override fun onStop() {
    guidancePopup?.dismiss()
    guidancePopup = null
    super.onStop()
}

Treat visibility and acknowledgement as separate states. A user may see guidance and dismiss it without accepting it, while another may complete the suggested action. This distinction is useful when measuring whether contextual help is effective.

Pattern Best suited to Typical trigger User dismissal
Tooltip Icon or control name Long press or hover Automatic timeout or pointer exit
Info bubble Contextual explanation or next step Tap on a trigger Outside tap or completed action
Snackbar Brief status message or undo option Event completion Timeout or swipe
Dialog Blocking decision Explicit user action A required choice

Designing for Australian use and accessibility

Australian apps are often used one-handed on crowded Sydney trains and Melbourne trams, so guidance should fit near the trigger without covering the primary action. Checkout journeys for services such as Woolworths or Coles also benefit from short explanations that disappear after the relevant step.

Australian English and familiar verbs help the interface feel local. Use wording such as “tap”, “save”, and “cancel”, along with terms like “authorise” where appropriate. Avoid long microcopy that requires users to decode technical language while standing in a queue.

Bright sunlight at an Australian bus stop can wash out low-contrast bubble colours, so test dark and light themes with strong contrast. The Australian Government Digital Service Standard reinforces accessible, inclusive design through WCAG-aligned requirements. TalkBack users also need the trigger and bubble content announced in a logical order, with a clear route back to the trigger.

Connecting guidance with app discovery

Developers who want to connect contextual help with search can use the toolbar search guide to place a SearchView in the app bar. A search hint should describe the expected result, while guidance near the search icon explains why the field appears or which filters are available.

After a user completes one guided action, avoid showing the same bubble on every screen. Store a small acknowledgement flag with SharedPreferences, but keep essential instructions visible in the underlying screen rather than relying on remembered help.

Search and guidance can share state: opening the search field can dismiss a nearby bubble, and selecting a result can acknowledge it. This prevents two overlays from competing for attention during a fast workflow.

Testing and maintaining guidance

Test tooltips and bubbles on several physical Android devices as well as in the emulator. Check long-press behaviour, tap-outside dismissal, rotation, large font settings, display scaling, dark mode, and TalkBack. Espresso can verify that an action dismisses a popup, while manual testing is still needed for placement near screen edges.

Keep stock, unmodified devices in the main test matrix because rooted firmware and modified system images can change focus, overlays, and accessibility behaviour. For workflows that involve rooted devices, consult a specialist reference such as Web RootSafe to assess the security implications.

Keep guidance strings in Android resources and review them when Android or Material updates alter interaction patterns. If interaction counts are collected, retain only privacy-safe measurements that reveal whether guidance is useful; effective help answers the immediate question and then leaves the screen unobstructed.