Substratum主题开发:查找并修改SystemUI的ToggleSliderView以定制亮度条
Hey there! I’ve messed around with similar Substratum theme tweaks before, so let’s break down how to tackle this brightness slider modification step by step.
First, let’s clear up what <com.android.systemui.settings.ToggleSliderView> is: it’s a custom View class built exclusively for SystemUI, not a standard Android widget. That’s why you don’t see the actual slider UI directly in the layout file—all the visual rendering and core logic are handled by this class, which pulls in resources like drawables, colors, and styles behind the scenes.
Here’s your actionable plan:
1. Locate the Resources ToggleSliderView Uses
You won’t need to edit the ToggleSliderView class itself for most visual tweaks—focus on the resources it references instead:
- Dig through SystemUI’s drawables: In your decompiled SystemUI project, check
res/drawable/for files linked to sliders, especially those named withbrightness,slider, ortoggle_slider(e.g.,brightness_slider_background.xml,toggle_slider_thumb.xml,slider_progress.xml). These define the slider’s track, thumb icon, and background shape. - Check styles and custom attributes: Look in
res/values/styles.xmlandres/values/attrs.xmlfor styles applied toToggleSliderView, or custom attributes it uses (likesliderTrackColor,sliderThumbTint). You’ll often find a dedicated style for the brightness slider here.
2. Override Resources in Your Substratum Theme
Substratum works by matching resource paths and names to replace SystemUI’s default assets. Here’s how to apply your custom style:
- Mirror the resource path: For example, if SystemUI uses
res/drawable/brightness_slider_progress.xml, create the exact same path in your Substratum theme project. - Replace with your design: Edit the XML file to use your own colors, gradients, or shapes. For instance, change the progress track color by modifying the
solidorgradientvalues in the drawable. - Adjust layout attributes (optional): If you want to tweak the slider’s size, padding, or position, copy
quick_settings_brightness_dialog.xmlto your theme’sres/layout/directory, then modify attributes likeandroid:layout_widthorandroid:paddingLefton theToggleSliderViewtag.
3. Advanced: Tweak ToggleSliderView Logic (If Needed)
If you need to change the slider’s behavior (e.g., adjust sensitivity, add custom animations), you’ll need to work with the class’s code:
- The smali code for
ToggleSliderViewlives insmali/com/android/systemui/settings/ToggleSliderView.smaliin your decompiled SystemUI folder. - You can modify this smali code (or inject patches) and include the modified class in your Substratum theme, but this is more advanced and requires familiarity with smali syntax.
Quick Example
Suppose you want to change the brightness slider’s thumb color:
- Find SystemUI’s
toggle_slider_thumb.xmlinres/drawable/. - Copy this file to your theme’s
res/drawable/directory. - Edit the file to replace the default color with your desired hex value (e.g., swap
#ff444444for#ff009688).
Once you build your Substratum theme, it will automatically replace SystemUI’s default slider resources with your custom ones.
内容的提问来源于stack exchange,提问作者Kureteiyu

