Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set textcolor button back to default

Tags:

android

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();
    }
}
like image 580
Robby Smet Avatar asked Dec 27 '22 18:12

Robby Smet


2 Answers

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...

like image 118
user370305 Avatar answered Jan 08 '23 14:01

user370305


Back up your default color in onCreate();

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

Then set it back

btn.setTextColor(defaultTextColor);
like image 28
Lazy Ninja Avatar answered Jan 08 '23 16:01

Lazy Ninja