2016-12-26 7 views
0

У меня есть запись на одной странице в приложении xamarin.forms, которое не работает должным образом на моем планшете. Когда я нажимаю на нее, появляется клавиатура, и я могу вводить текст, но ничего, кроме отображения заполнителя. это приложение работает с другими устройствами Android, но мой планшет не отображает входные данные. Таблетка: Galaxy Tab s - андроид 5,0 телефон: галактика s6 - андроид 6,0xamarin entry not work

<ContentPage 
    xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    x:Class="MyProject.MyPage" 
    Title="SomeTitle" 
    Padding="10, 40, 10, 10"> 
    <Entry Placeholder="Hi"/> 
</ContentPage> 
+0

I Изменить запись с ярлыком, но это не работает снова, когда в коде Установите это свойство текста. – Mohashan

+0

Не могли бы вы сообщить об этой проблеме https://bugzilla.xamarin.com/enter_bug.cgi?product=Forms? Спасибо –

ответ

0

В некоторых устройствах Samsung это происходит для этого вам нужно написать пользовательский визуализатор и попытаться установить цвет текста или BackgroundColor то он должен работать.

ИЛИ

попробовать XLabs Extended Entry

+0

Пользовательский контроль не работает ... – Mohashan

+0

попробуйте нижеследующий код –

0

Попробуйте

Использование:

ExtendedEntry entry = new ExtendedEntry 
{ 
    Text = "Dummy Text", 
    TextColor = Color.Black, 
    PlaceholderTextColor = Color.Black, 
}; 

PCL код

using Xamarin.Forms; 

namespace VHS.MobileApp.eVita.CustomViews 
{ 
    public class ExtendedEntry : Entry 
    { 
     /// <summary> 
     /// The font property 
     /// </summary> 
     public static readonly BindableProperty FontProperty = 
      BindableProperty.Create("Font", typeof(Font), typeof(ExtendedEntry), new Font()); 

     /// <summary> 
     /// The XAlign property 
     /// </summary> 
     public static readonly BindableProperty XAlignProperty = 
      BindableProperty.Create("XAlign", typeof(TextAlignment), typeof(ExtendedEntry), 
      TextAlignment.Start); 

     /// <summary> 
     /// The HasBorder property 
     /// </summary> 
     public static readonly BindableProperty HasBorderProperty = 
      BindableProperty.Create("HasBorder", typeof(bool), typeof(ExtendedEntry), true); 

     /// <summary> 
     /// The PlaceholderTextColor property 
     /// </summary> 
     public static readonly BindableProperty PlaceholderTextColorProperty = 
      BindableProperty.Create("PlaceholderTextColor", typeof(Color), typeof(ExtendedEntry), Color.Default); 

     /// <summary> 
     /// The MaxLength property 
     /// </summary> 
     public static readonly BindableProperty MaxLengthProperty = 
      BindableProperty.Create("MaxLength", typeof(int), typeof(ExtendedEntry), int.MaxValue); 

     /// <summary> 
     /// Gets or sets the MaxLength 
     /// </summary> 
     public int MaxLength 
     { 
      get { return (int)this.GetValue(MaxLengthProperty); } 
      set { this.SetValue(MaxLengthProperty, value); } 
     } 

     /// <summary> 
     /// Gets or sets the Font 
     /// </summary> 
     public Font Font 
     { 
      get { return (Font)GetValue(FontProperty); } 
      set { SetValue(FontProperty, value); } 
     } 

     /// <summary> 
     /// Gets or sets the X alignment of the text 
     /// </summary> 
     public TextAlignment XAlign 
     { 
      get { return (TextAlignment)GetValue(XAlignProperty); } 
      set { SetValue(XAlignProperty, value); } 
     } 

     /// <summary> 
     /// Gets or sets if the border should be shown or not 
     /// </summary> 
     public bool HasBorder 
     { 
      get { return (bool)GetValue(HasBorderProperty); } 
      set { SetValue(HasBorderProperty, value); } 
     } 

     /// <summary> 
     /// Sets color for placeholder text 
     /// </summary> 
     public Color PlaceholderTextColor 
     { 
      get { return (Color)GetValue(PlaceholderTextColorProperty); } 
      set { SetValue(PlaceholderTextColorProperty, value); } 
     } 

     public static readonly BindableProperty BorderRadiusProperty = 
     BindableProperty.Create<ExtendedEntry, float>(p => p.BorderRadius, default(float)); 

     public float BorderRadius 
     { 
      get { return (float)GetValue(BorderRadiusProperty); } 
      set { SetValue(BorderRadiusProperty, value); } 
     } 

    } 
} 

Droid Код:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 

using Android.App; 
using Android.Content; 
using Android.OS; 
using Android.Runtime; 
using Android.Views; 
using Android.Widget; 
using Xamarin.Forms.Platform.Android; 
using Xamarin.Forms; 
using VHS.MobileApp.eVita.CustomViews; 
using Android.Graphics; 
using Android.Text.Method; 
using Android.Util; 
using Color = Xamarin.Forms.Color; 
using VHS.MobileApp.eVita.Droid.CustomRenderer; 
using System.ComponentModel; 
using Android.Text; 


[assembly: ExportRenderer(typeof(ExtendedEntry), typeof(ExtendedEntryRenderer))] 
namespace VHS.MobileApp.eVita.Droid.CustomRenderer 
{ 

    public class ExtendedEntryRenderer : EntryRenderer 
    { 

     protected ExtendedEntryRenderer(IntPtr javaReference, JniHandleOwnership transfer) 
     { 

     } 

     public ExtendedEntryRenderer() 
      : base() 
     { 

     } 

     private const int MinDistance = 10; 

     /// <summary> 
     /// Called when [element changed]. 
     /// </summary> 
     /// <param name="e">The e.</param> 
     protected override void OnElementChanged(ElementChangedEventArgs<Entry> e) 
     { 
      base.OnElementChanged(e); 
      var view = (ExtendedEntry)Element; 

      if (Control != null && e.NewElement != null && e.NewElement.IsPassword) 
      { 
       Control.SetTypeface(Typeface.Default, TypefaceStyle.Normal); 
       Control.TransformationMethod = new PasswordTransformationMethod(); 
       this.Control.SetBackgroundColor(Android.Graphics.Color.White); 
      } 


      #region SETTING CUSTOM FONT 

      if (view.FontFamily != null && view.FontFamily != string.Empty) 
      { 
       Typeface typeface = Typeface.CreateFromAsset(Forms.Context.Assets, view.FontFamily); 
       Control.Typeface = typeface; 
      } 

      #endregion 

      // SetFont(view); 
      SetTextAlignmentWithVerticalFill(view); 
      SetPlaceholderTextColor(view); 
      SetMaxLength(view); 
     } 

     /// <summary> 
     /// Handles the touch. 
     /// </summary> 
     /// <param name="sender">The sender.</param> 
     /// <param name="e">The <see cref="Android.Views.View.TouchEventArgs"/> instance containing the event data.</param> 
     /*void HandleTouch(object sender, TouchEventArgs e) 
     { 
      var element = (ExtendedEntry)this.Element; 
      switch (e.Event.Action) 
      { 
       case MotionEventActions.Down: 
        this.downX = e.Event.GetX(); 
        this.downY = e.Event.GetY(); 
        return; 
       case MotionEventActions.Up: 
       case MotionEventActions.Cancel: 
       case MotionEventActions.Move: 
        this.upX = e.Event.GetX(); 
        this.upY = e.Event.GetY(); 

        float deltaX = this.downX - this.upX; 
        float deltaY = this.downY - this.upY; 

        // swipe horizontal? 
        if (Math.Abs(deltaX) > Math.Abs(deltaY)) 
        { 
         if (Math.Abs(deltaX) > MinDistance) 
         { 
          if (deltaX < 0) 
          { 
           element.OnRightSwipe(this, EventArgs.Empty); 
           return; 
          } 

          if (deltaX > 0) 
          { 
           element.OnLeftSwipe(this, EventArgs.Empty); 
           return; 
          } 
         } 
         else 
         { 
          Log.Info("ExtendedEntry", "Horizontal Swipe was only " + Math.Abs(deltaX) + " long, need at least " + MinDistance); 
          return; // We don't consume the event 
         } 
        } 
        // swipe vertical? 
        //     else 
        //     { 
        //      if(Math.abs(deltaY) > MIN_DISTANCE){ 
        //       // top or down 
        //       if(deltaY < 0) { this.onDownSwipe(); return true; } 
        //       if(deltaY > 0) { this.onUpSwipe(); return true; } 
        //      } 
        //      else { 
        //       Log.i(logTag, "Vertical Swipe was only " + Math.abs(deltaX) + " long, need at least " + MIN_DISTANCE); 
        //       return false; // We don't consume the event 
        //      } 
        //     } 

        return; 
      } 
     }*/ 

     /// <summary> 
     /// Handles the <see cref="E:ElementPropertyChanged" /> event. 
     /// </summary> 
     /// <param name="sender">The sender.</param> 
     /// <param name="e">The <see cref="System.ComponentModel.PropertyChangedEventArgs"/> instance containing the event data.</param> 
     protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) 
     { 
      var view = (ExtendedEntry)Element; 
      this.Control.SetBackgroundColor(Android.Graphics.Color.White); 
      //if (e.PropertyName == ExtendedEntry.FontProperty.PropertyName) 
      //{ 
      // SetFont(view); 
      //} 
      //else 

      if (e.PropertyName == ExtendedEntry.XAlignProperty.PropertyName) 
      { 
       SetTextAlignmentWithVerticalFill(view); 
      } 
      else if (e.PropertyName == ExtendedEntry.HasBorderProperty.PropertyName) 
      { 
       //return; 
      } 
      else if (e.PropertyName == ExtendedEntry.PlaceholderTextColorProperty.PropertyName) 
      { 
       SetPlaceholderTextColor(view); 
      } 
      else 
      { 
       base.OnElementPropertyChanged(sender, e); 
       if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName) 
       { 
        this.Control.SetBackgroundColor(view.BackgroundColor.ToAndroid()); 
       } 
      } 
     } 

     /// <summary> 
     /// Sets the text alignment. 
     /// </summary> 
     /// <param name="view">The view.</param> 
     private void SetTextAlignmentWithVerticalFill(ExtendedEntry entry) 
     { 
      switch (entry.XAlign) 
      { 
       case Xamarin.Forms.TextAlignment.Center: 
        Control.Gravity = GravityFlags.Center; 
        break; 
       case Xamarin.Forms.TextAlignment.End: 
        Control.Gravity = GravityFlags.End | GravityFlags.CenterVertical; 
        break; 
       case Xamarin.Forms.TextAlignment.Start: 
        Control.Gravity = GravityFlags.Start | GravityFlags.CenterVertical; 
        break; 
      } 
     } 

     /// <summary> 
     /// Sets the color of the placeholder text. 
     /// </summary> 
     /// <param name="view">The view.</param> 
     private void SetPlaceholderTextColor(ExtendedEntry view) 
     { 
      if (view.PlaceholderTextColor != Color.Default) 
      { 
       Control.SetHintTextColor(view.PlaceholderTextColor.ToAndroid()); 
      } 
     } 

     /// <summary> 
     /// Sets the MaxLength characteres. 
     /// </summary> 
     /// <param name="view">The view.</param> 
     private void SetMaxLength(ExtendedEntry view) 
     { 
      Control.SetFilters(new IInputFilter[] { new InputFilterLengthFilter(view.MaxLength) }); 
     } 
    } 
}