activity_main.xml :

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">


    <ImageView
        android:id="@+id/image"
        android:layout_width="300dp"
        android:layout_height="200dp"
        app:srcCompat="@drawable/ic_launcher_background"
        tools:layout_editor_absoluteX="43dp"
        tools:layout_editor_absoluteY="29dp" />

    <TextView
        android:id="@+id/result"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#FFFFFF"
        android:text="image is visible"
        android:textColor="@color/black"
        android:textSize="20sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.564"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/image"
        app:layout_constraintVertical_bias="0.17" />

    <ToggleButton
        android:id="@+id/toggleButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ToggleButton"
        android:textOff="Hide Image"
        android:textOn="Show image"
        tools:layout_editor_absoluteX="179dp"
        tools:layout_editor_absoluteY="516dp"
        app:layout_constraintTop_toBottomOf="@id/result"/>


</android.support.constraint.ConstraintLayout>

---------------------------------------------------------------------------

MainActivity.kt :


    class MainActivity : AppCompatActivity() {
    lateinit var image:ImageView
    lateinit var result: TextView
    lateinit var toggleButton: ToggleButton

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        toggleButton=findViewById(R.id.toggleButton)
        image=findViewById(R.id.image)
        result=findViewById(R.id.result)

        toggleButton.setOnCheckedChangeListener{ compoundButton , isChecked ->

            if(isChecked){
                image.visibility=View.INVISIBLE
                result.text="the image is invisible"
            }
            else{
                image.visibility=View.VISIBLE
                result.text="The image is visible"
            }
        }
    }
}