Search code examples
xamarinbackgroundxamarin.formsrendererxamarin.forms.entry

Xamarin Forms. Keyboard on android covers bottom of an entry with custom background


I use an entry in XF with custom background for Android platform. When it is focused the keyboard covers bottom line of entry.

public class MessageEntryRenderer : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
    {
        base.OnElementChanged(e);
        if (e.OldElement != null || this.Element == null)
            return;

        Control.Gravity = DefaultGravity;

        var MessageEntry = Element as MessageEntry;
        UpdateBackground(MessageEntry);
        ...            
    }

private void UpdateBackground(MessageEntry MessageEntry)
    {
        if (_renderer != null)
        {
            _renderer.Dispose();
            _renderer = null;
        }
        _renderer = new BorderRenderer();
        //Set to background object of type GradientDrawable
        Control.SetBackground(_renderer.GetBorderBackground(MessageEntry.BorderColor, MessageEntry.BackgroundColor, MessageEntry.BorderWidth, MessageEntry.BorderRadius));
    } }

Pictures: Entry with borders Keyboard covers bottom I need to show bottom line. I tried to add padding like this: private void UpdatePadding(MessageEntry MessageEntry) { Control.SetPadding((int)Forms.Context.ToPixels(MessageEntry.LeftPadding), 10, (int)Forms.Context.ToPixels(MessageEntry.RightPadding), 0);
}
But it is padding for text inside entry.


Solution

  • I fixed it. The problem was with padding for entry. It was 0 for bottom and top. I set it as shown in following code:

    private void UpdatePadding(MessageEntry MessageEntry)
        {
            Control.SetPadding((int)Forms.Context.ToPixels(MessageEntry.LeftPadding), Control.PaddingTop/3,
                (int)Forms.Context.ToPixels(MessageEntry.RightPadding), Control.PaddingTop/3);
        }