简体   繁体   English

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

[英]How to place the emoji keyboard icon?

I am making a custom control of an entry.我正在制作一个条目的自定义控件。 I would like that when you open the keyboard, that icon appears on the keyboard.我希望当您打开键盘时,该图标会出现在键盘上。

在此处输入图片说明

I saw that it could be done by setting the InputType to Android.Text.InputTypes.TextVariationShortMessage |我看到可以通过将 InputType 设置为 Android.Text.InputTypes.TextVariationShortMessage 来完成。 Android.Text.InputTypes.ClassText. Android.Text.InputTypes.ClassText。 The problem is that I don't know how to implement it using a custom control.问题是我不知道如何使用自定义控件来实现它。

Custom Control xaml:自定义控件 xaml:

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

Custom control xaml.cs:自定义控件 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(Color), 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(string), 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(ImageSource), 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:主页.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:视图模型.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", ColorButton = "#B52D50", MethodCommandName = "twitter" });
        ItemList.Add(new Items { Image = "insta.png", ColorButton = "#B52D50", MethodCommandName = "insta" });
        ItemList.Add(new Items { Image = "web.png", ColorButton = "#B52D50", 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;

            }



        }
    }

}

The screenshot you provided needs to do with your custom keyboard.您提供的屏幕截图需要与您的自定义键盘有关。 It is impossible without creating your own keyboard, due to Android and iOS platform limitations.由于 Android 和 iOS 平台的限制,不创建自己的键盘是不可能的。

We could create our own keyboard view including a few emojis as buttons and some control else.我们可以创建自己的键盘视图,包括一些表情符号作为按钮和一些其他控件。 And add a TapGestureRecognizer to your image.并将TapGestureRecognizer添加到您的图像中。 When this Tapped event fires, it would show your custom keyboard view.当此 Tapped 事件触发时,它会显示您的自定义键盘视图。

For the custom keyboard view, you could check the link below.对于自定义键盘视图,您可以查看下面的链接。 Xamarin Android: Issues with Custom Keyboard Of Custom Renderer - Appears Underneath Controls, Keys Not Pressable, etc Xamarin Android:自定义渲染器的自定义键盘问题 - 出现在控件下方、按键不可按下等

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM