我想在xamarin android中显示编辑文本的下划线颜色。我怎么能这样做。
这是我的代码
_editText = new EditText(Activity);
_editText.SetBackgroundResource(Resource.Drawable.border);
_editText.SetTextColor(_black);
_editText.SetHintTextColor(_black);
_editText.Hint = "Please enter the Title";
_editText.LayoutParameters = new TableRow.LayoutParams(150, TableRow.LayoutParams.FillParent, 1);
答案 0 :(得分:1)
从Sdk版本21(又名Lollipop)及以上版本中,您应使用BackgroundTinList
属性,以获得较低的sdk使用Background.SetColorFilter
方法。例如
public class MainActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
var layout = new LinearLayout(this);
var editText = new EditText(this)
{
LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent)
};
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
{
editText.BackgroundTintList = ColorStateList.ValueOf(Color.Green);
}
else
{
editText.Background.SetColorFilter(Color.Green, PorterDuff.Mode.SrcAtop);
}
layout.AddView(editText);
SetContentView(layout);
}
}
结果: