Android中的问题渲染开关

时间:2020-03-03 17:53:13

标签: android android-switch switchcompat

我正在尝试使用Android的Switch组件,但是在单击它时,我得到了不希望看到的视图,它一次显示2个状态(选中和未选中)。

我也使用了自定义样式,但没有成功。以下是我的自定义样式。我在一个片段中使用了相同的观点,在那里我没有遇到任何问题,但是在另一项活动中却遇到了这个问题。任何人都可以提出问题所在吗?我已经使用了所有版本,例如Switch,SwitchMaterial,SwitchCompat,但是发生了同样的问题。

<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>

下面是Switch xml文件:

<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" />

Output image

0 个答案:

没有答案
相关问题