Reputation: 455
I am trying to use Switch component of Android but while clicking on it, I am getting below view which is not desired, it is showing 2 states at a time (checked as well as unchecked).
I also used custom style but getting no success. Below is my custom style. I have used the same view in a fragment, there I am facing no issue, but in another activity I am getting this issue. Can anyone suggest what the problem might be? I have used all variations like Switch, SwitchMaterial, SwitchCompat but same issue is occuring.
<style name="Switch_Veg_Only" parent="Theme.AppCompat.Light">
<!-- active thumb & track color (30% transparency) -->
<item name="colorControlActivated">@color/green</item>
<!-- inactive thumb color -->
<item name="colorSwitchThumbNormal">@color/grey
</item>
<!-- inactive track color (30% transparency) -->
<item name="android:colorForeground">#42221f1f
</item>
</style>
Below is the Switch xml file:
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/activity_filter_switch_veg_only"
android:theme="@style/Switch_Veg_Only"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="@id/activity_filter_text_view_filter"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="@id/activity_filter_text_view_filter"
android:layout_gravity="end"
android:checked="false"
android:text="@string/fragment_home_veg_only"
android:textColor="@color/DarkGrey"
android:textAllCaps="true"
android:textOn="a"
android:textOff="b"
android:textSize="@dimen/fragment_home_veg_only"
app:switchPadding="8dp" />
Upvotes: 1
Views: 181