システムの字幕設定を適用する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Android TV には、ユーザーが独自の字幕スタイルを定義できる設定が用意されています。
このガイドでは、システム提供のトークンをアプリが取得して適用する方法について説明します。
設定します。
字幕オプションは [設定] >システム >ユーザー補助 >キャプション:

CaptioningManager を取得する
アクティビティから、Context
を使用して字幕サービスを取得できます。
CaptioningManager
:
CaptioningManager captioningManager = (CaptioningManager)context.getSystemService(Context.CAPTIONING_SERVICE);
字幕スタイルの変更を処理する
次に、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();
}
});
システムの CaptionStyle
を取得するには、getUserStyle()
を呼び出します。
直接:
CaptionStyle systemCaptionStyle = captioningManager.getUserStyle();
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-07-27 UTC。
[null,null,["最終更新日 2025-07-27 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();"]]