Android Question insert an image into an edittext

Nkalampika

Active Member
Licensed User
Hello I would like to insert an image in an edittext as an emoticon. how to do it
 

Nkalampika

Active Member
Licensed User
here is a screenshot
 

Attachments

  • Screenshot_2018-09-03-00-17-53.png
    Screenshot_2018-09-03-00-17-53.png
    433.9 KB · Views: 321
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
Edittext, Labels etc. have Background property, which maybe a drawable resource.
Seach Google by words shape selector layer-list background and you will find a lot of xml examples.
 
Upvote 0

Nkalampika

Active Member
Licensed User
I would like to put an image in the edittext how to do knowing that I am creating my own emoticon
 

Attachments

  • Screenshot_2018-09-05-01-25-37.png
    Screenshot_2018-09-05-01-25-37.png
    348.4 KB · Views: 192
Upvote 0

npsonic

Active Member
Licensed User
Your question doesn't tell much when considered what Emoticon keyboard really means.

What you most likely want to do is to create grid for emojis. When you click emoji in grid it appears in text field?
You can achieve something like this in many ways. None of those ways are quick to build, but lets begin with few steps.

1. Decide what emojis you want to use and consider licenses ex. are you breaking the license if you share your app with those emojis.

2. You need working layout for your emoji keyboard. Use grid lib for this step with the view pager. Each page will contain grid for the group of emojis.

3. How you want to show emojis in each cell is up to you, but I would probably just add label for each cell and add unicode emoji as an text. When you are using lib like EmoijIX you get Apple style emojis.

4. When you click any of the emojis you can just copy text from label in that cell to end of the text field.
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
If to come back to original question ...
If you want "own emoticon", you can create own ttf and use CSBuilder, like in following sample.
Here I used system font (Android 5+). But It's possible to use ttf from assets.

B4X:
Sub Process_Globals
End Sub

Sub Globals
    Dim EditText                                                                As EditText
    Dim Panel                                                                   As Panel
    Dim typefaceInstance                                                        As Object   ' Android Typeface
End Sub

Sub Activity_Create(FirstTime As Boolean)

    Dim javaobjectInstance                                                      As JavaObject
  
    javaobjectInstance.InitializeContext
    ' typefaceInstance = javaobjectInstance.RunMethod ("TypefaceFromAssets", Array ("MyOwnFont.ttf"))
    typefaceInstance = javaobjectInstance.RunMethod ("TypefaceFromFile",   Array ("/system/fonts/NotoColorEmoji.ttf"))
      
    Activity.Color = Colors.RGB (0, 128, 0)
    Panel.Initialize ("")
    Activity.AddView (Panel, 5%x, 20dip, 90%x, 100dip)
    Dim cd As ColorDrawable
    cd.Initialize (Colors.RGB( 255, 240, 240), 20dip)
    Panel.Background = cd
  
    EditText.Initialize ("")
    Panel.AddView (EditText, 50dip, 0dip, Panel.Width - 100dip, Panel.Height)
End Sub

Sub Activity_Resume

    Dim csbuilderInstance1                                                       As CSBuilder
  
    csbuilderInstance1.Initialize.Append ("Qu-qu  ").Typeface (typefaceInstance).Size(24).Append (Chr (0xD83D) & Chr (0xDE02)).PopAll
    csbuilderInstance1.Append ("  Lja-lja  ").Typeface (typefaceInstance).Size(24).Append (Chr (0xD83D) & Chr (0xDE04)).PopAll
    EditText.TextColor = Colors.Black
    EditText.Text = csbuilderInstance1
  

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

#If Java
import     android.graphics.Typeface;
public Typeface TypefaceFromAssets (String filename) { return Typeface.createFromAsset (activityBA.context.getAssets(), filename); }  
public Typeface TypefaceFromFile   (String filename) { return Typeface.createFromFile (filename); }
#End If
 
Last edited:
Upvote 0
Top