tubi_tv_drawable_subtitles_on_selector.xml
Overview
`tubi_tv_drawable_subtitles_on_selector.xml` is an Android drawable selector resource file. Its primary purpose is to define different drawable images for a UI element representing the "subtitles on" state in the Tubi TV application, specifically changing the visual appearance of the subtitle icon based on the element's pressed state.
This XML file enables dynamic UI feedback by switching between two drawable resources when the user interacts with the subtitles toggle button or icon. It improves user experience by visually indicating the press state with a faded version of the subtitle icon.
Detailed Explanation
Root Element: <selector>
Namespace:
xmlns:android="http://schemas.android.com/apk/res/android"Purpose: Declares that this XML file defines a state list drawable, which is a drawable object containing multiple images for different states (like pressed, focused, disabled) of a UI widget.
Child Elements: <item>
Each `` tag inside the `` specifies a drawable resource and the state conditions under which it should be applied.
Item | Attributes | Description |
|---|---|---|
1 | `android:drawable="@drawable/tubi_tv_subtitles_on"` | Drawable for the subtitles icon when the button is **not pressed**. This is the default visual state when the user is not interacting with the button. |
2 | `android:drawable="@drawable/tubi_tv_subtitles_on_faded"` | Drawable for the subtitles icon when the button **is pressed**. This faded image visually indicates a pressed or active interaction state. |
3 | `android:drawable="@drawable/tubi_tv_subtitles_on"` | Default drawable (fallback), used if no other state matches. Ensures the icon is displayed even if the state is undefined. |
Usage
This selector is typically referenced in a layout XML or programmatically in code to set the background or image drawable of a UI component such as an `ImageButton`, `ToggleButton`, or `ImageView` that controls subtitle toggling.
Example in Layout XML:
<ImageButton
android:id="@+id/subtitles_toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/tubi_tv_drawable_subtitles_on_selector"
android:contentDescription="@string/subtitles_toggle_desc"/>
Behavior:
When the user presses the subtitles toggle button, the icon changes to the faded version (
tubi_tv_subtitles_on_faded).When the button is released, the icon returns to the normal appearance (
tubi_tv_subtitles_on).
Important Implementation Details
State Management: This selector uses only the
state_pressedattribute to manage states. It does not handle other states likestate_focused,state_enabled, orstate_selected.Drawables: The referenced drawables (
tubi_tv_subtitles_onandtubi_tv_subtitles_on_faded) must exist as image resources (e.g., PNG, SVG) in the project'sres/drawabledirectory.Performance: Using a selector drawable avoids programmatic changes to UI elements for different states, leveraging Android's native state list drawable mechanism for efficient state changes.
Interaction with Other Parts of the System
UI Layer: This drawable selector is part of the user interface layer. It is linked to subtitle toggle controls that allow users to switch subtitles on or off.
Related Drawable Resources: It depends on the existence of
tubi_tv_subtitles_onandtubi_tv_subtitles_on_fadeddrawable resources which visually represent the subtitles enabled state.Event Handling: It works in conjunction with event listeners in the code that handle subtitle toggling logic, but it strictly controls only the visual representation.
Visual Diagram
The following **Mermaid flowchart** illustrates the state-based flow of drawable selection within this selector file:
flowchart TD
A[Start: Subtitle toggle button state] --> B{Is button pressed?}
B -- Yes --> C[tubi_tv_subtitles_on_faded drawable]
B -- No --> D[tubi_tv_subtitles_on drawable]
C --> E[Display faded subtitle icon]
D --> F[Display normal subtitle icon]
E --> G[End]
F --> G
Summary
`tubi_tv_drawable_subtitles_on_selector.xml` is a simple yet effective resource that controls the subtitle icon's appearance based on user interaction. It improves the user experience by providing immediate visual feedback when toggling subtitles on the Tubi TV app. It is a reusable component that interacts closely with drawable assets and UI controls in the application’s interface layer.
If you need to modify the behavior (e.g., add more states such as focused or disabled), you can extend this selector by adding more `` elements with appropriate state attributes and drawable references.