Is it possible to change the size of icon inside EditText

后端 未结 3 1900
南旧
南旧 2021-02-20 09:56

I am creating a login window with username and password fields and in each I would like to put icons. When I add icon to EditText field I cannot change the size of icon.

3条回答
  •  日久生厌
    2021-02-20 10:44

    You can change the icon and use a smaller one on focus. This is the method you should use.

    public void setCompoundDrawablesWithIntrinsicBounds (
                                           int left, int top, int right, int bottom)
    

    Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text. Use 0 if you do not want a Drawable there. The Drawables' bounds will be set to their intrinsic bounds.

    Now to add padding you can use this

     public void setCompoundDrawablePadding (int pad)
    

    Sets the size of the padding between the compound drawables and the text.

    Related XML Attributes:

    android:drawablePadding
    

    More information here and here. There are many other methods you might find interesting.

提交回复
热议问题