[英]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.但是,即使我想将按钮的 TextColor 设置为上面的颜色,它也不会从默认的深色禁用状态文本颜色更改。 How can I change the TextColor for my button?
如何更改按钮的 TextColor?
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.这适用于 Xamarin.Forms Android 应用程序。
btn.SetTextColor(Color.Rgb(0:255, 0:255, 0:255));
mBtnEmail.setTextColor(ContextCompat.getColor(getContext(), R.color.text_gray));
In xamarin forms android, I just did this in my styles.xml
for my disabled textcolor
.在 xamarin forms android 中,我只是在我的
styles.xml
为我禁用的textcolor
做了这个。 I'm sure it's the same for button textcolor
.我确定按钮
textcolor
是一样的。
<item name="android:textColor">@android:color/black</item>
You can change it using NextButton.ForeColor = Color.FromRgba(0xFF, 0xFF, 0xFF, 0x80);
您可以使用
NextButton.ForeColor = Color.FromRgba(0xFF, 0xFF, 0xFF, 0x80);
更改它. .
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.