如何从Code显示OFF状态

时间:2016-09-23 08:46:29

标签: android android-layout

我的活动中有Switch,用户点击它即可启用或禁用设置。我将Switch当前条件存储在静态变量中。

现在,交换机始终处于ON状态,即使用户禁用它,它也会在Activity上禁用,但是当我重新启动活动时它处于打开状态。

我想知道如何从代码设置OFF切换状态。

<Switch
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/switchNotifications"
    android:layout_centerHorizontal="true"
    android:paddingTop="150dp"
    android:text="@string/notification_settings"
    android:textColor="@color/white"
    android:checked="true"
    android:textSize="18sp"
    android:layout_marginLeft="24dp"
    android:layout_marginRight="24dp"
    android:fontFamily="sans-serif-medium"
    android:theme="@style/SCBSwitch"
    />

JAVA

    switchBtn = (Switch) findViewById(R.id.switchNotifications);
    switchBtn.  //What to write here to OFF switch from CODE.

1 个答案:

答案 0 :(得分:1)