
como cambiar color boton al dar click android studio kotlin?
Publicado por camilo andres (3 intervenciones) el 21/07/2021 21:53:57
Buenas tardes:
Estoy haciendo mi primera app en android studio con kotlin y me funciona bien, es para enviar datos a mysql.
lo que no he podido hace es que cuando presione el boton insertar, este cambie de color y lo mantenga, osea no en el click.presed sino en el evento clickBtnInsertar. lo tengo declarado como btn1
Estoy haciendo mi primera app en android studio con kotlin y me funciona bien, es para enviar datos a mysql.
lo que no he podido hace es que cuando presione el boton insertar, este cambie de color y lo mantenga, osea no en el click.presed sino en el evento clickBtnInsertar. lo tengo declarado como btn1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package com.example .bee
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import android.widget.Toast
import com.android.volley.Request
import com.android.volley.Response
import com.android.volley.toolbox.StringRequest
import com.android.volley.toolbox.Volley
class MainActivity : AppCompatActivity() {
var txtVelocidadRalenti: EditText?=null
var txtTemperatura: EditText?=null
var txtCrucero: EditText?=null
var btn1:Button?=null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
txtVelocidadRalenti=findViewById(R.id.txtVelocidadRalenti)
txtTemperatura=findViewById(R.id.txtTemperatura)
txtCrucero=findViewById(R.id.txtCrucero)
btn1=findViewById(R.id.btnInsertar)
}
fun clickBtnInsertar(view:View){
val url="http://192.168.10.14/Ralenti/insertar.php"
val queue=Volley.newRequestQueue(this)
var resultadoPost = object : StringRequest(
Request.Method.POST,url,
Response.Listener<String> { response ->
Toast.makeText(this,"Se enviaron Rpm Ralenti",Toast.LENGTH_LONG).show()
},Response.ErrorListener { error ->
Toast.makeText(this,"Error $error ",Toast.LENGTH_LONG).show()
}){
override fun getParams(): MutableMap<String, String> {
val parametros=HashMap<String,String>()
parametros.put("VelocidadRalenti",txtVelocidadRalenti?.text.toString())
parametros.put("Temperatura",txtTemperatura?.text.toString())
return parametros
}
}
queue.add(resultadoPost)
}
fun clickBtnCrucero(view:View){
val url="http://192.168.10.14/Crucero/insertar.php"
val queue=Volley.newRequestQueue(this)
var resultadoPost = object : StringRequest(
Request.Method.POST,url,
Response.Listener<String> { response ->
Toast.makeText(this,"Se enviaron Rpm Crucero",Toast.LENGTH_LONG).show()
},Response.ErrorListener { error ->
Toast.makeText(this,"Error $error ",Toast.LENGTH_LONG).show()
}){
override fun getParams(): MutableMap<String, String> {
val parametros=HashMap<String,String>()
parametros.put("VelocidadCrucero",txtCrucero?.text.toString())
parametros.put("Temperatura",txtTemperatura?.text.toString())
return parametros
}
}
queue.add(resultadoPost)
}
fun clickBtnIniciar(view:View){
val url="http://192.168.10.14/Abrir/insertar.php"
val queue=Volley.newRequestQueue(this)
var resultadoPost = object : StringRequest(
Request.Method.POST,url,
Response.Listener<String> { response ->
Toast.makeText(this,"Se envio",Toast.LENGTH_LONG).show()
},Response.ErrorListener { error ->
Toast.makeText(this,"Error $error ",Toast.LENGTH_LONG).show()
}){
override fun getParams(): MutableMap<String, String> {
val parametros=HashMap<String,String>()
parametros.put("Encender","SI".toString())
return parametros
}
}
queue.add(resultadoPost)
}
fun clickBtnCerrar(view:View){
val url="http://192.168.10.14/Cerrar/insertar.php"
val queue=Volley.newRequestQueue(this)
var resultadoPost = object : StringRequest(
Request.Method.POST,url,
Response.Listener<String> { response ->
Toast.makeText(this,"Se envio",Toast.LENGTH_LONG).show()
},Response.ErrorListener { error ->
Toast.makeText(this,"Error $error ",Toast.LENGTH_LONG).show()
}){
override fun getParams(): MutableMap<String, String> {
val parametros=HashMap<String,String>()
parametros.put("Apagar","SI".toString())
return parametros
}
}
queue.add(resultadoPost)
}
}
Valora esta pregunta


0