Euridice01
Euridice01

Reputation: 2568

How can I change the text color of a disabled button?

Currently, I have something like this inside my view:

public void DisableNextBtn(object sender, TextChangedEventArgs e)
{
    if (String.IsNullOrEmpty(emailentry.Text))
    {
        NextButton.IsEnabled = false;
        NextButton.TextColor = Color.FromRgba(0xFF, 0xFF, 0xFF, 0x80);
    }
    else
    {
        NextButton.IsEnabled = true;
        NextButton.TextColor = Color.White;
    }
}

However, even though I want to set the TextColor of the button to the color above, it won't change from the default dark disabled state text color. How can I change the TextColor for my button?

I have a custom button already, so I was thinking maybe there is a way to change the textcolor of disabled state button inside my custom renderer but I'm not entirely sure.

This is for Xamarin.Forms Android app.

Upvotes: 3

Views: 6993

Answers (6)

Eddie Gordon
Eddie Gordon

Reputation: 1

This might not be a workable solution for everybody, but in order to get around this I changed the MouseDownBackColor and MouseOverBackColor to match the setting I was using for the BackColor, this way I could leave the button enabled and use it just to display text with a transparent background as none of the text box components allow a transparent background to be used.

Upvotes: 0

roudlek
roudlek

Reputation: 385

if you'd like to change the color so it becomes like the color of it background, wich means you want to hide the text, you can do:

button1.Text = "";
button1.Enabled = true;

Upvotes: 0

AbdelAziz AbdelLatef
AbdelAziz AbdelLatef

Reputation: 3744

You can change it using NextButton.ForeColor = Color.FromRgba(0xFF, 0xFF, 0xFF, 0x80);.

Upvotes: 0

BillyMartin
BillyMartin

Reputation: 116

In xamarin forms android, I just did this in my styles.xml for my disabled textcolor. I'm sure it's the same for button textcolor.

<item name="android:textColor">@android:color/black</item>

Upvotes: 0

Karim Elshaweish
Karim Elshaweish

Reputation: 39

            btn.SetTextColor(Color.Rgb(0:255, 0:255, 0:255));

Upvotes: 2

Shweta Chauhan
Shweta Chauhan

Reputation: 6981

mBtnEmail.setTextColor(ContextCompat.getColor(getContext(), R.color.text_gray));

Upvotes: 0

Related Questions