title: How to change TextView background color while it's pressed down?
body: <p>I try to change background of TextView1 while it's pressed down. This is my text.xml in drawable folder:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;item android:state_pressed="true" android:drawable="@android:color/white" /&gt;
      &lt;item android:drawable="@android:color/black"/&gt;
  &lt;/selector&gt;
  </code></pre>
  
  <p>And this is my Kotlin file:</p>
  
  <pre><code>override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_app)
  
          var textview1 = findViewById(R.id.TextView1) as TextView
  
          textview1.setOnClickListener{
              val t = TextView(this)
              t.setBackgroundResource(R.drawable.text)
          }
      }
  </code></pre>
  
  <p>I did this according to this answered answer: <a href="https://stackoverflow.com/questions/24602190/programatically-make-textview-background-color-change-while-pressed">Programatically make TextView background color change while pressed</a></p>
  
  <p>TextView1:</p>
  
  <pre><code>&lt;TextView
          android:id="@+id/TextView1"
          android:layout_width="50dp"
          android:layout_height="50dp"/&gt;
  </code></pre>
  
  <p>Does anybody know what I'm missing? I'm begginer.</p>
  
  <hr>
  
  <p>Sorry, it was my mistake in code. The correct code is:</p>
  
  <pre><code> var textview1 = findViewById(R.id.TextView1) as TextView
  
          textview1.setOnClickListener {
              //val t = TextView(this)
              textview1.setBackgroundResource(R.drawable.text)
  </code></pre>