Adopt system caption settings
Stay organized with collections
Save and categorize content based on your preferences.
On Android TV, settings are provided for users to define their own caption style.
This guide demonstrates how an app can obtain and apply the system-provided
caption style.
The caption options can be found under Settings > System > Accessibility > Caption:

Obtain the CaptioningManager
From an activity, you can get the caption service from its Context
using
CaptioningManager
:
CaptioningManager captioningManager = (CaptioningManager)context.getSystemService(Context.CAPTIONING_SERVICE);
Handle caption style changes
You can then handle caption style changes by implementing CaptioningChangeListener
:
if (captioningManager != null) {
// Define a class to store the CaptionStyle details.
CurrentCaptionStyle currentCaptionStyle = new CurrentCaptionStyle;
// Define the listeners.
captioningManager.addCaptioningChangeListener(new CaptioningChangeListener() {
@Override
public void onEnabledChanged(boolean enabled) {
super.onEnabledChanged(enabled);
Log.d(TAG, "onEnabledChanged");
currentCaptionStyle.isEnabled = enabled;
}
@Override
public void onLocaleChanged(@Nullable Locale locale) {
super.onLocaleChanged(locale);
Log.d(TAG, "onLocaleChanged");
currentCaptionStyle.locale = locale;
}
@Override
public void onFontScaleChanged(float fontScale) {
super.onFontScaleChanged(fontScale);
Log.d(TAG, "onFontScaleChanged");
currentCaptionStyle.fontScale = fontScale;
}
@Override
public void onUserStyleChanged(@NonNull CaptionStyle userStyle) {
super.onUserStyleChanged(userStyle);
Log.d(TAG, "onUserStyleChanged");
currentCaptionStyle.hasBackgroundColor = userStyle.hasBackgroundColor();
currentCaptionStyle.backgroundColor = userStyle.backgroundColor;
currentCaptionStyle.backgroundOpcity = userStyle.backgroundColor >>> 24;
currentCaptionStyle.hasForegroundColor = userStyle.hasForegroundColor();
currentCaptionStyle.foregroundColor = userStyle.foregroundColor;
currentCaptionStyle.foregroundOpacity = userStyle.foregroundColor >>> 24;
currentCaptionStyle.hasWindowColor = userStyle.hasWindowColor();
currentCaptionStyle.windowColor = userStyle.windowColor;
currentCaptionStyle.windowOpcity = userStyle.windowColor >>> 24;
currentCaptionStyle.hasEdgeColor = userStyle.hasEdgeColor();
currentCaptionStyle.edgeColor = userStyle.edgeColor;
currentCaptionStyle.hasEdgeType = userStyle.hasEdgeType();
currentCaptionStyle.edgeType = userStyle.edgeType;
currentCaptionStyle.typeFace = userStyle.getTypeface();
}
});
To obtain the system CaptionStyle
, you can call getUserStyle()
directly:
CaptionStyle systemCaptionStyle = captioningManager.getUserStyle();
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# Adopt system caption settings\n\nOn Android TV, settings are provided for users to define their own caption style.\nThis guide demonstrates how an app can obtain and apply the system-provided\ncaption style.\n\nThe caption options can be found under **Settings \\\u003e System \\\u003e Accessibility \\\u003e Caption**:\n\nObtain the CaptioningManager\n----------------------------\n\nFrom an activity, you can get the caption service from its `Context` using\n[`CaptioningManager`](https://developer.android.com/reference/android/view/accessibility/CaptioningManager): \n\n CaptioningManager captioningManager = (CaptioningManager)context.getSystemService(Context.CAPTIONING_SERVICE);\n\nHandle caption style changes\n----------------------------\n\nYou can then handle caption style changes by implementing [`CaptioningChangeListener`](/reference/android/view/accessibility/CaptioningManager.CaptioningChangeListener): \n\n if (captioningManager != null) {\n // Define a class to store the CaptionStyle details.\n CurrentCaptionStyle currentCaptionStyle = new CurrentCaptionStyle;\n // Define the listeners.\n captioningManager.addCaptioningChangeListener(new CaptioningChangeListener() {\n\n @Override\n public void onEnabledChanged(boolean enabled) {\n super.onEnabledChanged(enabled);\n Log.d(TAG, \"onEnabledChanged\");\n currentCaptionStyle.isEnabled = enabled;\n }\n\n @Override\n public void onLocaleChanged(@Nullable Locale locale) {\n super.onLocaleChanged(locale);\n Log.d(TAG, \"onLocaleChanged\");\n currentCaptionStyle.locale = locale;\n }\n\n @Override\n public void onFontScaleChanged(float fontScale) {\n super.onFontScaleChanged(fontScale);\n Log.d(TAG, \"onFontScaleChanged\");\n currentCaptionStyle.fontScale = fontScale;\n }\n\n @Override\n public void onUserStyleChanged(@NonNull CaptionStyle userStyle) {\n super.onUserStyleChanged(userStyle);\n Log.d(TAG, \"onUserStyleChanged\");\n currentCaptionStyle.hasBackgroundColor = userStyle.hasBackgroundColor();\n currentCaptionStyle.backgroundColor = userStyle.backgroundColor;\n currentCaptionStyle.backgroundOpcity = userStyle.backgroundColor \u003e\u003e\u003e 24;\n currentCaptionStyle.hasForegroundColor = userStyle.hasForegroundColor();\n currentCaptionStyle.foregroundColor = userStyle.foregroundColor;\n currentCaptionStyle.foregroundOpacity = userStyle.foregroundColor \u003e\u003e\u003e 24;\n currentCaptionStyle.hasWindowColor = userStyle.hasWindowColor();\n currentCaptionStyle.windowColor = userStyle.windowColor;\n currentCaptionStyle.windowOpcity = userStyle.windowColor \u003e\u003e\u003e 24;\n currentCaptionStyle.hasEdgeColor = userStyle.hasEdgeColor();\n currentCaptionStyle.edgeColor = userStyle.edgeColor;\n currentCaptionStyle.hasEdgeType = userStyle.hasEdgeType();\n currentCaptionStyle.edgeType = userStyle.edgeType;\n currentCaptionStyle.typeFace = userStyle.getTypeface();\n }\n\n });\n\nTo obtain the system `CaptionStyle`, you can call `getUserStyle()`\ndirectly: \n\n CaptionStyle systemCaptionStyle = captioningManager.getUserStyle();"]]