Android webview although powerful, however, it often depends on Android components. The general usage of these components is unnecessary here, and there are many interesting usage methods in these components. For example, developers who have used QQ for Android may find that when entering chat records, you can directly put the emoticon image in edittext component ( 3 ). Many beginners may feel that it is difficult to implement the function , but it is actually easier to implement this function.
We generally useEdittextOfSettextMethodSetEdittextFor exampleCodeDirectionEdittextAdded a string.
Edittext=(Edittext) findbyview (R. Id. edittext );
Edittext. settext ("TestData");
We only need to do a little bit of the above Code to insert the imageEdittext. If you have read 《Android/ophoneDevelop a complete handout, you will find that the book uses text markup in many cases (similarHtmlLanguage labels, but only contain very limitedHtmlLanguage functions ). There isMark. With this tag, you can easily insert an imageEdittext. HoweverA tag has one more step than other labels.ImagegetterInterface to obtainDrawableObject. Let's take a look at the following code:
-
- Imagegetter = new imagegetter ()
-
- {
-
-
- @ Override
-
- Public drawable getdrawable (string source)
- {
-
- Int id = integer. parseint (source );
-
- Drawable d = getresources (). getdrawable (ID );
-
- D
-
- . Setbounds (0, 0, D. getintrinsicwidth (), d
-
- . Getintrinsicheight ());
-
- Return D;
-
- }
-
- };
Copy code
The above code passes throughImagegetterInterfaceGetdrawableMethod returnsDrawableObject, whereSourceThe parameter value isLabelSRCAttribute Value. We need to use the following codeLabel.
Edittext.AppEnd (html. fromhtml ("
+ Faces [new random (). nextint (6)] + "'/>", imagegetter, null ));
Where Faces Is Int Type array, saving the corresponding Drawable ResourcesOf IDValue. In use Use Html. fromhtml Method To encapsulate these labels. Label. Fromhtml Method 2 Parameter (s) specified Imagegetter Object Label SRC Attribute to obtain the corresponding Drawable Object. Pass Edittext. append Insert Method The system willAutomaticSet The label is converted to the corresponding image and displayed in Edittext . Let's take a look at our results ( 4 ).