TransWikia.com

Botón permanezca cambiado de color al ser usado

Stack Overflow en español Asked by jose Velasquez on January 1, 2021

Buenas tardes quisiera que al haber apretado un botón de los 14 que tengo este permanezca de otro color ya que tienen que ser usados uno por día y así no genere confusión ya que quedara marcado los ya utilizados.

Este es mi Codigo activity de los botones:

package com.mic.misprimerospasosenlasantidad;

 import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.android.material.floatingactionbutton.FloatingActionButton;

public class Semanav1 extends AppCompatActivity implements View.OnClickListener{

ImageView back;
Button bt1,bt2,bt3,bt4,bt5,bt6,bt7,bt8,bt9,bt10,bt11,bt12,bt13,bt14;
TextView tv_prin;

FloatingActionButton mas, menos;
private int ValorTexto = 0;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_semanav1);
    back = (ImageView) findViewById(R.id.backanw);
    back.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onBackPressed();
        }
    });

    mas=(FloatingActionButton) findViewById(R.id.btncm);
    menos=(FloatingActionButton) findViewById(R.id.btncmn);

    String text1=" example";




    tv_prin=(TextView)findViewById(R.id.tv_prin);
    tv_prin.setText(text1);

    if (ValorTexto == 0){
        ValorTexto = 20;
        tv_prin.setTextSize(ValorTexto);
    }
    mas.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (ValorTexto == 0){
                ValorTexto = 20;
            }
            if (ValorTexto < 50){
                ValorTexto = ValorTexto + 2;
                tv_prin.setTextSize(ValorTexto);
            }
        }
    });
    menos.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (ValorTexto == 0){
                ValorTexto = 20;
            }
            if (ValorTexto > 10){
                ValorTexto = ValorTexto - 2;
                tv_prin.setTextSize(ValorTexto);
            }
        }
    });

    bt1=(Button)findViewById(R.id.btn1);
    bt2=(Button)findViewById(R.id.btn2);
    bt3=(Button)findViewById(R.id.btn3);
    bt4=(Button)findViewById(R.id.btn4);
    bt5=(Button)findViewById(R.id.btn5);
    bt6=(Button)findViewById(R.id.btn6);
    bt7=(Button)findViewById(R.id.btn7);
    bt8=(Button)findViewById(R.id.btn8);
    bt9=(Button)findViewById(R.id.btn9);
    bt10=(Button)findViewById(R.id.btn10);
    bt11=(Button)findViewById(R.id.btn11);
    bt12=(Button)findViewById(R.id.btn12);
    bt13=(Button)findViewById(R.id.btn13);
    bt14=(Button)findViewById(R.id.btn14);

    bt1.setOnClickListener(this);
    bt2.setOnClickListener(this);
    bt3.setOnClickListener(this);
    bt4.setOnClickListener(this);
    bt5.setOnClickListener(this);
    bt6.setOnClickListener(this);
    bt7.setOnClickListener(this);
    bt8.setOnClickListener(this);
    bt9.setOnClickListener(this);
    bt10.setOnClickListener(this);
    bt11.setOnClickListener(this);
    bt12.setOnClickListener(this);
    bt13.setOnClickListener(this);
    bt14.setOnClickListener(this);


}
@Override
public void onClick(View v){

    TextView tvnamed = (TextView)findViewById(R.id.tvnamed);


    switch (v.getId()){
        case R.id.btn1:
            Intent intent1 = new Intent(getApplicationContext(), dia.class);
            intent1.putExtra("1",1);
            startActivity(intent1);

            break;
        case R.id.btn2:
            Intent intent2 = new Intent(getApplicationContext(), dia.class);
            intent2.putExtra("1",2);
            startActivity(intent2);

            break;
        case R.id.btn3:
            Intent intent3 = new Intent(getApplicationContext(), dia.class);
            intent3.putExtra("1",3);
            startActivity(intent3);

            break;


        case R.id.btn4:

                 Intent intent4 = new Intent(getApplicationContext(), dia.class);
                 intent4.putExtra("1",4);
                    startActivity(intent4);

                            break;



        case R.id.btn5:
            Intent intent5 = new Intent(getApplicationContext(), dia.class);
            intent5.putExtra("1",5);
            startActivity(intent5);

            break;
        case R.id.btn6:
            Intent intent6 = new Intent(getApplicationContext(), dia.class);
            intent6.putExtra("1",6);
            startActivity(intent6);

            break;
        case R.id.btn7:
            Intent intent7 = new Intent(getApplicationContext(), dia.class);
            intent7.putExtra("1",7);
            startActivity(intent7);

            break;
        case R.id.btn8:
            Intent intent8 = new Intent(getApplicationContext(), dia.class);
            intent8.putExtra("1",8);
            startActivity(intent8);

            break;
        case R.id.btn9:
            Intent intent9 = new Intent(getApplicationContext(), dia.class);
            intent9.putExtra("1",9);
            startActivity(intent9);

            break;
        case R.id.btn10:
            Intent intent10 = new Intent(getApplicationContext(), dia.class);
            intent10.putExtra("1",10);
            startActivity(intent10);

            break;
        case R.id.btn11:
            Intent intent11 = new Intent(getApplicationContext(), dia.class);
            intent11.putExtra("1",11);
            startActivity(intent11);

            break;
        case R.id.btn12:
            Intent intent12 = new Intent(getApplicationContext(), dia.class);
            intent12.putExtra("1",12);
            startActivity(intent12);

            break;
        case R.id.btn13:
            Intent intent13 = new Intent(getApplicationContext(), dia.class);
            intent13.putExtra("1",13);
            startActivity(intent13);

            break;
        case R.id.btn14:
            Intent intent14 = new Intent(getApplicationContext(), dia.class);
            intent14.putExtra("1",14);
            startActivity(intent14);

            break;

    }
}

}

y este el xml de la activity mencionada : v

LinearLayout 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"
android:orientation="vertical"
tools:context=".Semanav1">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorCelesteclaro"
        android:orientation="horizontal">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="4"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/backanw"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:layout_margin="4dp"
                app:srcCompat="@drawable/abc_vector_test" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical">

            <TextView
                android:id="@+id/tv"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:gravity="center"
                android:paddingRight="50dp"
                android:text="CASTIDAD Y PUREZA"
                android:textColor="#FFFEFE"
                android:textSize="24sp" />

        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="15dp"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/imageView4"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                tools:srcCompat="@tools:sample/avatars" />

            <ScrollView
                android:id="@+id/defv"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="22.5dp"
                android:layout_weight="100"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/tv_prin"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:justificationMode="inter_word"
                    android:text=" example "
                    android:textSize="20sp" />
            </ScrollView>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.5"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:layout_marginBottom="5dp"
                    android:layout_weight="20"
                    android:text="Días :"
                    android:textSize="20sp"
                    app:fontFamily="sans-serif-black" />

                <com.google.android.material.floatingactionbutton.FloatingActionButton
                    android:id="@+id/btncm"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="right"
                    android:layout_marginRight="10dp"
                    android:layout_weight="1"
                    android:background="@drawable/mas"
                    android:foreground="@drawable/mas"
                    app:backgroundTint="#F6F3F3"
                    tools:visibility="visible" />

                <com.google.android.material.floatingactionbutton.FloatingActionButton
                    android:id="@+id/btncmn"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="right"
                    android:layout_weight="1"
                    android:background="@drawable/menos"
                    android:foreground="@drawable/menos"
                    android:visibility="visible"
                    app:backgroundTint="#FFFFFF" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:orientation="horizontal">

                    <Button
                        android:id="@+id/btn1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        android:layout_weight="1"
                        android:background="@drawable/btn"
                        android:text="1"
                        android:textColor="#FFFFFF"
                        android:textSize="20sp" />

                    <Button
                        android:id="@+id/btn2"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        android:layout_weight="1"
                        android:background="@drawable/btn"
                        android:text="2"
                        android:textColor="#FFFFFF"
                        android:textSize="20sp" />

                    <Button
                        android:id="@+id/btn3"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        android:layout_weight="1"
                        android:background="@drawable/btn"
                        android:text="3"
                        android:textColor="#FFFFFF"
                        android:textSize="20sp" />

                    <Button
                        android:id="@+id/btn4"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        android:layout_weight="1"
                        android:background="@drawable/btn"
                        android:text="4"
                        android:textColor="#FFFFFF"
                        android:textSize="20sp" />

                    <Button
                        android:id="@+id/btn5"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        android:layout_weight="1"
                        android:background="@drawable/btn"
                        android:text="5"
                        android:textColor="#FFFFFF"
                        android:textSize="20sp" />

                    <Button
                        android:id="@+id/btn6"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        android:layout_weight="1"
                        android:background="@drawable/btn"
                        android:text="6"
                        android:textColor="#FFFFFF"
                        android:textSize="20sp" />

                    <Button
                        android:id="@+id/btn7"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        android:layout_weight="1"
                        android:background="@drawable/btn"
                        android:text="7"
                        android:textColor="#FFFFFF"
                        android:textSize="20sp" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:orientation="horizontal">

                    <Button
                        android:id="@+id/btn8"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        android:layout_weight="1"
                        android:background="@drawable/btn"
                        android:text="8"
                        android:textColor="#FFFFFF"
                        android:textSize="20sp" />

                    <Button
                        android:id="@+id/btn9"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        android:layout_weight="1"
                        android:background="@drawable/btn"
                        android:text="9"
                        android:textColor="#FFFFFF"
                        android:textSize="20sp" />

                    <Button
                        android:id="@+id/btn10"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        android:layout_weight="1"
                        android:background="@drawable/btn"
                        android:text="10"
                        android:textColor="#FFFFFF"
                        android:textSize="20sp" />

                    <Button
                        android:id="@+id/btn11"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        android:layout_weight="1"
                        android:background="@drawable/btn"
                        android:text="11"
                        android:textColor="#FFFFFF"
                        android:textSize="20sp" />

                    <Button
                        android:id="@+id/btn12"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        android:layout_weight="1"
                        android:background="@drawable/btn"
                        android:text="12"
                        android:textColor="#FFFFFF"
                        android:textSize="20sp" />

                    <Button
                        android:id="@+id/btn13"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        android:layout_weight="1"
                        android:background="@drawable/btn"
                        android:text="13"
                        android:textColor="#FFFFFF"
                        android:textSize="20sp" />

                    <Button
                        android:id="@+id/btn14"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        android:layout_weight="1"
                        android:background="@drawable/btn"
                        android:text="14"
                        android:textColor="#FFFFFF"
                        android:textSize="20sp" />
                </LinearLayout>

            </LinearLayout>

        </LinearLayout>
    </LinearLayout>

</LinearLayout>

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP