Robby Smet
Robby Smet

Reputation: 4661

Set textcolor button back to default

I have a loginscreen. In this loginscreen I have a button that is by default disabled.

When the user has entered 4 numbers I enable the button and change the textcolor to green.
But when the 4 numbers are not the correct code I clear my edittext and disable my button again.

At the moment the textcolor of this disabled button is offcourse green. How can I set it back to the default color?

public void onTextChanged(CharSequence s, int start, int before, int count) {
            if(s.length() >= maxLength)
            {
                btnOk.setEnabled(true);
                btnOk.setTextColor(Color.parseColor("#00B32D"));
            }

            else
            {
                btnOk.setEnabled(false);
            }


private void checkIfValid(String inputPin)
{
    if(inputPin.equals("0000"))
    {
        startActivity(new Intent(this, ShowScreenActivity.class));
        finish();
    }
    else
    {
        clearText();

      ====>   //Here i want to set my textcolor back to normal.  

        Toast.makeText(this, "Pincode foutief", Toast.LENGTH_SHORT).show();
    }
}

Upvotes: 5

Views: 4858

Answers (3)

Tim D
Tim D

Reputation: 690

If you have another button that always maintains default color, you can set the color of your color-modified button to this other button to get back to default. The code might be...

btnOk.setTextColor(btnCancel.getTextColors());

This is a simple one line solution, but you have to be careful the other button color is not being modified for other reasons or this may not work.

Upvotes: 0

user370305
user370305

Reputation: 109237

Get the default color of Button using this code,

int DefaultButtonColor = btnOk.getTextColors().getDefaultColor();

If its not what you are looking for, then you can get Android Platform Resource Color using

something like,

android.R.color.secondary_text_dark

Check others too...

Upvotes: 8

Lazy Ninja
Lazy Ninja

Reputation: 22527

Back up your default color in onCreate();

defaultTextColor = btnOk.getTextColors().getDefaultColor();

Then set it back

btn.setTextColor(defaultTextColor);

Upvotes: 3

Related Questions