如何放置表情符号键盘图标?

问题描述

我正在对条目进行自定义控件。我希望当您打开键盘时,该图标会出现在键盘上。

enter image description here

我看到可以通过将InputType设置为Android.Text.InputTypes.TextvariationShortMessage来完成此操作。 Android.Text.InputTypes.Classtext。问题是我不知道如何使用自定义控件来实现它。

自定义控件xaml:

  <Entry
                        x:Name="EntryControl"
                        Margin="45,0"
                        Keyboard="Chat"
                        Placeholder="{Binding Placeholder}"
                        Text="{Binding EntryText}"
                        WidthRequest="320" />

自定义控件xaml.cs:

 public partial class CKEditor : ContentView
{
    public CKEditor()
    {
        InitializeComponent();
    }
    //NO ESTA LISTO TODAVIA


    //===============Placeholder=====================
    public static readonly BindableProperty TextProperty =
            BindableProperty.Create("Text",typeof(string),typeof(CKEditor));

    public string Text
    {
        get { return (string)GetValue(TextProperty); }
        set { SetValue(TextProperty,value); }
    }


    //===============Item Source==========================
    public static readonly BindableProperty EmojiItemSourceProperty =
            BindableProperty.Create("EmojiItemSource",typeof(IList),typeof(CKEditor));

    public IList EmojiItemSource
    {
        get { return (IList)GetValue(EmojiItemSourceProperty); }
        set { SetValue(EmojiItemSourceProperty,value); }
    }


    //===============Border Color=====================
    public static readonly BindableProperty BorderColorProperty =
            BindableProperty.Create("BorderColor",typeof(Color),typeof(CKEditor));

    public Color BorderColor
    {
        get { return (Color)GetValue(BorderColorProperty); }
        set { SetValue(BorderColorProperty,value); }
    }

    //===============Border Color=====================
    public static readonly BindableProperty SendButtonColorProperty =
            BindableProperty.Create("SendButtonColor",typeof(CKEditor));

    public Color SendButtonColor
    {
        get { return (Color)GetValue(SendButtonColorProperty); }
        set { SetValue(SendButtonColorProperty,value); }
    }


    //===============Corner radius=====================
    public static readonly BindableProperty CornerRadiusProperty =
            BindableProperty.Create("CornerRadius",typeof(int),typeof(CKEditor));

    public int CornerRadius
    {
        get { return (int)GetValue(CornerRadiusProperty); }
        set { SetValue(CornerRadiusProperty,value); }
    }


   

    //===============Left side Icon=====================
    public static readonly BindableProperty LeftSideIconProperty =
            BindableProperty.Create("LeftSideIcon",typeof(ImageSource),typeof(CKEditor));

    public ImageSource LeftSideIcon
    {
        get { return (ImageSource)GetValue(LeftSideIconProperty); }
        set { SetValue(LeftSideIconProperty,value); }
    }


    //===============Placeholder=====================
    public static readonly BindableProperty PlaceholderProperty =
            BindableProperty.Create("Placeholder",typeof(CKEditor));

    public string Placeholder
    {
        get { return (string)GetValue(PlaceholderProperty); }
        set { SetValue(PlaceholderProperty,value); }
    }

    //===============Send message command=====================
    public static readonly BindableProperty SendMsgCommandProperty =
            BindableProperty.Create("SendMsgCommand",typeof(ICommand),typeof(CKEditor));

    public ICommand SendMsgCommand
    {
        get { return (ICommand)GetValue(SendMsgCommandProperty); }
        set { SetValue(SendMsgCommandProperty,value); }
    }


    //===============Right side icon=====================
    public static readonly BindableProperty RightSideIconProperty =
            BindableProperty.Create("RightSideIcon",typeof(CKEditor));

    public ImageSource RightSideIcon
    {
        get { return (ImageSource)GetValue(RightSideIconProperty); }
        set { SetValue(RightSideIconProperty,value); }
    }
    //===============Visibility EmojiBox===============


    public static readonly BindableProperty BoxVisibleProperty =
        BindableProperty.Create("BoxVisible",typeof(bool),typeof(CKEditor));

    public bool BoxVisible
    {
        get { return (bool)GetValue(BoxVisibleProperty); }
        set { SetValue(BoxVisibleProperty,value); }
    }

}

MainPage.xaml:

        <StackLayout AbsoluteLayout.LayoutBounds="0,1,AutoSize,AutoSize" AbsoluteLayout.LayoutFlags="PositionProportional">
            <fav:CKEditor
                x:Name="entrycontrol"
                BorderColor="{Binding BorderColor}"
                BoxVisible="{Binding IsVisible}"
                CornerRadius="{Binding CornerRadius}"
                EmojiItemSource="{Binding EmojiList}"
                LeftSideIcon="{Binding LeftSideIcon}"
                Placeholder="{Binding Placeholder}"
                RightSideIcon="{Binding RightSideIcon}"
                Text="{Binding EntryText}" />
        </StackLayout>

viewmodel.cs:

 public class viewmodel : INotifyPropertyChanged
{
    //==============================================================
    public event PropertyChangedEventHandler PropertyChanged;

    protected virtual void OnPropertyChanged(string propertyName = "")
    {
        PropertyChanged?.Invoke(this,new PropertyChangedEventArgs(propertyName));
    }
    //==============================================================



    string imageprimarybutton;
    public string Firstimage
    {
        get => imageprimarybutton; set
        {
            imageprimarybutton = value;
            OnPropertyChanged();
        }
    }

    //=============

    string firstButtonColor;
    public string FirstButtonColor
    {
        get => firstButtonColor; set
        {
            firstButtonColor = value;
            OnPropertyChanged();
        }
    }

    //=============

    private bool isVisible;

    public bool IsVisible
    {
        get => isVisible;
        set
        {
            isVisible = value;
            OnPropertyChanged();
        }
    }

    //=============


    public ICommand OpenFloating { get; private set; }

    public ICommand MethodCommand { get; set; }

    public ObservableCollection<Items> ItemList { get; set; }

    //=============

    public viewmodel()
    {
        IsVisible = false;
        Firstimage = "dots.png";
        FirstButtonColor = "#B52D50";

        OpenFloating = new Command(openFloatingButton);

     
        ItemList = new ObservableCollection<Items>();

        ItemList.Add(new Items { Image = "facebook.png",ColorButton = "#B52D50",MethodCommandName = "facebook" });
        ItemList.Add(new Items { Image = "twitter.png",MethodCommandName = "twitter" });
        ItemList.Add(new Items { Image = "insta.png",MethodCommandName = "insta" });
        ItemList.Add(new Items { Image = "web.png",MethodCommandName = "web" });

        MethodCommand = new Command(ButtonCommand);


    }



    //Sirve tanto para ir a aplicaciones como para ir a paginas web o lugares de la propia aplicacion
    private void ButtonCommand(object obj)
    {
        string itemName = obj as string;


        if (itemName == "facebook")
        {

            switch (Device.RuntimePlatform)
            {
                case Device.iOS:
                    Launcher.TryOpenAsync("http://facebook.com/");
                    break;
                case Device.Android:
                    DependencyService.Get<IOpenApps>().openFacebook();
                    break;
            }


        }
        else if (itemName == "twitter")
        {
            switch (Device.RuntimePlatform)
            {
                case Device.iOS:
                    Launcher.TryOpenAsync("http://twitter.com/");
                    break;
                case Device.Android:
                    DependencyService.Get<IOpenApps>().openTwitter();
                    break;
            }
        }
        else if (itemName == "insta")
        {
            switch (Device.RuntimePlatform)
            {
                case Device.iOS:
                    Launcher.TryOpenAsync("http://instagram.com/");
                    break;
                case Device.Android:
                    DependencyService.Get<IOpenApps>().openInstagram();
                    break;
            }
        }
        else if (itemName == "web")
        {

            Launcher.TryOpenAsync("https://web.icam.es/");


        }
    }


    bool firstStart = true;
    bool nextClick = true;

    public void openFloatingButton()
    {

        if (firstStart)
        {
           

            Firstimage = "cross.png";
            FirstButtonColor = "#6F1B31";


            IsVisible = true;
            firstStart = false;

        }
        else
        {
            if (nextClick)
            {
              
                Firstimage = "dots.png";
                FirstButtonColor = "#B52D50";

                IsVisible = false;
                nextClick = false;
            }
            else
            {
                
                Firstimage = "cross.png";
                FirstButtonColor = "#6F1B31";

                IsVisible = true;
                nextClick = true;

            }



        }
    }

}

解决方法

您提供的屏幕截图需要使用自定义键盘。由于Android和iOS平台的限制,如果不创建自己的键盘是不可能的。

我们可以创建自己的键盘视图,包括一些表情符号作为按钮以及一些其他控件。并将TapGestureRecognizer添加到图像中。当触发此事件时,它将显示您的自定义键盘视图。

对于自定义键盘视图,您可以检查下面的链接。 Xamarin Android: Issues with Custom Keyboard Of Custom Renderer - Appears Underneath Controls,Keys Not Pressable,etc

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...