是否可以在EditText中更改图标的大小 [英] Is it possible to change the size of icon inside EditText

查看:381
本文介绍了是否可以在EditText中更改图标的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个包含用户名和密码字段的登录窗口,每个窗口我都想放置图标.当我在EditText字段中添加图标时,无法更改图标的大小.

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.

图标位于EditText字段内,因为我想在聚焦时更改EditText背景.

Icon is inside EditText field because I want to change EditText background when it is focused.

我试图将图标和EditText视图放入LinearLayout中,但是当EditText聚焦时我无法更改布局背景.

I tried to put icon and EditText view inside LinearLayout, but I couldn't change layout background when EditText is focused.

我的EditText代码:

My EditText code:

<EditText
    android:id="@+id/user_name_edit_text"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="35dp"
    android:layout_marginRight="35dp"
    android:layout_marginTop="35dp"
    android:background="@drawable/custom_border_selector"
    android:drawablePadding="5dp"
    android:hint="@string/username"
    android:singleLine="true"
    android:textColor="#757575"
    android:textSize="15sp"
    android:drawableLeft="@drawable/ic_person_grey_24dp"
    />

EditText视觉效果:

EditText visual:

推荐答案

您可以更改图标并在焦点上使用较小的图标.这是您应该使用的方法.

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)

将Drawables(如果有)设置为显示在文本的左侧,上方,右侧和下方.如果您不希望在此处使用Drawable,请使用0. Drawables的边界将设置为其固有边界.

现在要添加填充,您可以使用此

Now to add padding you can use this

 public void setCompoundDrawablePadding (int pad)

设置复合可绘制对象和文本之间的填充大小.

相关的XML属性:

android:drawablePadding

更多信息此处此处.您可能会发现许多其他有趣的方法.

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

这篇关于是否可以在EditText中更改图标的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆