Java Android: on a white background, the switchcompat trace is not visible
•
Android
I have an activity with a white background and added a switchcompat, but when the switch is not active (off), the track is invisible. What is visible is only the thumb, so for the user, it is not a switch at all. How to make the track of the switch visible when the switch is in the inactive position?
<android.support.v7.widget.SwitchCompat
android:id="@+id/someswitchname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
/>
resolvent:
This is done by defining a custom theme as follows:
<style name="Custom.SwitchCompat.WhiteTrack" parent="Base.Widget.AppCompat.CompoundButton.Switch">
<!-- Inactive track color(30% transparency) -->
<item name="android:colorForeground">[some color]</item>
</style>
Then define a theme in your layout like this:
android:theme="@style/Custom.SwitchCompat.WhiteTrack"
Wait
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码