Is it possible to change the colour of the line below / Border of a TextBox (Entry)
you can use custom renderer that will affect all entries,
here's for android:
[assembly: ExportRenderer(typeof(Entry), typeof(MyEntryRenderer))]
namespace Android.MyRenderers
{
public class MyEntryRenderer : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control == null || e.NewElement == null) return;
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
Control.BackgroundTintList = ColorStateList.ValueOf(Color.White);
else
Control.Background.SetColorFilter(Color.White, PorterDuff.Mode.SrcAtop);
}
}
}
and iOS:
[assembly: ExportRenderer (typeof(Entry), typeof(MyEntryRenderer))]
namespace iOS.MyRenderers
{
public class MyEntryRenderer : EntryRenderer
{
private CALayer _line;
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged (e);
_line = null;
if (Control == null || e.NewElement == null)
return;
Control.BorderStyle = UITextBorderStyle.None;
_line = new CALayer {
BorderColor = UIColor.FromRGB(174, 174, 174).CGColor,
BackgroundColor = UIColor.FromRGB(174, 174, 174).CGColor,
Frame = new CGRect (0, Frame.Height / 2, Frame.Width * 2, 1f)
};
Control.Layer.AddSublayer (_line);
}
}
}
not sure about Windows solution on this
How to change textField underline color?
** See update below or see the answer by @GJJ2019 **
The logical answer would be to use an InputBorder, particularly an UnderlineInputDecorator, and pass it in to the inputdecorator as the border. However, all this does is tell the InputDecorator whether is should use an underline or whatever else you specify.
The actual color is based on the theme - from the source:
Color _getActiveColor(ThemeData themeData) {
if (isFocused) {
switch (themeData.brightness) {
case Brightness.dark:
return themeData.accentColor;
case Brightness.light:
return themeData.primaryColor;
}
}
return themeData.hintColor;
}
So to change the colour do something like this (or specify the theme for your entire application):
new Theme(
data: new ThemeData(
primaryColor: Colors.red,
accentColor: Colors.orange,
hintColor: Colors.green
),
child: new TextField(
decoration: new InputDecoration(
hintText: "Enter your email",
labelText: "Email",
labelStyle: new TextStyle(color: const Color(0xFF424242)),
border: new UnderlineInputBorder(
borderSide: new BorderSide(
color: Colors.red
)
)
),
),
),
UPDATE:
This is now possible to do in the way you'd expect it to work.
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: theColor),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: theColor),
),
border: UnderlineInputBorder(
borderSide: BorderSide(color: theColor),
),
)
Xamarin Entry bottom line color doesn`t change
In xaml you are using the default Entry
control and not your CustomEntryRenderer
which is what your renderer is affecting. Also, you might want to rename it because it is not actually your renderer, but your custom control.
To resolve your issue you can either change your renderer typeof(CustomEntryRenderer)
to typeof(Entry)
to affect all Android entries in your app by default. For example, this worked for my test app for all Entries:
[assembly: ExportRenderer(typeof(Entry), typeof(MyEntryRenderer))]
namespace YourNameSpace
{
public class MyEntryRenderer : EntryRenderer
{
public MyEntryRenderer(Context context) : base(context) { }
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control == null || e.NewElement == null) return;
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
Control.BackgroundTintList = ColorStateList.ValueOf(Android.Graphics.Color.White);
else
Control.Background.SetColorFilter(Android.Graphics.Color.White, PorterDuff.Mode.SrcAtop);
}
}
}
The other option is to switch your xaml code in MainPage
to actually use your custom control. For example, <local:CustomEntryRenderer/>
How to change border color of the html input when
Attach blur
event to the input
.
document.querySelectorAll('input').forEach((input) => { input.addEventListener('blur', function() { this.classList.toggle('green', this.value.length > 0); });});
.green { border: 2px solid green;}
<input type="text"><input type="text"><button>Click Me</button>
Xamarin Forms - Change cursor colour and bottom border using XAML
Changing the colorAccent
value in styles.xml (in Xamarin.Android project) will change the colour of the cursor and the bottom border of an Entry
field.
<item name="colorAccent">#BA55D3</item>
How to color input border bottom using CSS
The border is red in your example:
.numero { border-bottom: 1px solid #F00;}
<input type="number" id="nc" name="days" class="numero" placeholder="" min="0"><br />
How to change Flutter TextField border color on focus?
Add focusBorder insted of enabledBorder
TextFormField(
decoration: InputDecoration(
labelText: "Resevior Name",
fillColor: Colors.white,
focusedBorder:OutlineInputBorder(
borderSide: const BorderSide(color: Colors.white, width: 2.0),
borderRadius: BorderRadius.circular(25.0),
),
),
)
Customizing Borders on a TextBox
I was able to create a design near the one in your image but not in the way you want it.
Here's the one I managed to make:
What I used:
textbox
for the search inputlabel
for clearing the input,line shape
(found inVisual Basic PowerPacks
in the toolbox) for the border effect
OR- another
label
having a longunderscore
( _ ). - and a
picturebox
for the search icon
Procedure:
For the textbox
, set these properties:
BorderStyle : None
BackColor: 0, 188, 212
(or the color of your form's background) but that's the exact color based on the image you providedForeColor: White
For the clear button, I just used a label
(it still has a click event), set the text to: "✖" and the BackColor
to Transparent
.
For the border
effect, just draw a line shape below the textbox
then set:
BorderColor: White
BorderWidth
to3
If you are using the label
with underscores, just place it under the textbox
.
Sorry got bored that I even included everything even though you're just asking for the border
(still wondering why did I answer this on the first place). I hope this can still be of any help.
Related Topics
Download a File from Azure Devops Server Writes Wrong Data to The File
C# List - Removing Items While Looping/Iterating
Finding the Concrete Type Behind an Interface Instance
Why Is ASP.NET Identity Identitydbcontext a Black-Box
Instantiate a Class from Its Textual Name
How to Write My C++ Function So I Can Call It from C#
ASP.NET Core MVC - Client-Side Validation for Custom Attribute
Creating Simple C++.Net Wrapper. Step-By-Step
Sharing Variables Between C# and C++
How Are Dlls Loaded by the Clr
ASP.NET 5 Add Wcf Service Reference
Error 0X80005000 and Directoryservices
Is a Finally Block Without a Catch Block a Java Anti-Pattern