Android 关于在控件一侧加入图标 以及调整图标的大小

加入图标可以在xml中,使用drawableLeft(Right\ Bottom\Top)属性

    <EditText
        android:id="@+id/psw"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="24dp"
        android:layout_marginTop="26dp"
        android:layout_marginEnd="24dp"
        android:hint="请输入原密码"
        android:inputType="textPassword"
        android:drawableLeft="@drawable/chgpwd1"
        android:selectAllOnFocus="true"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/wrx1" />

但Google设计的不是特别好,不能再xml调整控件中小图标的大小,但可以在代码中设置

 		psw = (EditText) findViewById(R.id.psw);
        Drawable drawable1=getResources().getDrawable(R.drawable.chgpwd1);
        drawable1.setBounds(0,0,50,50);
        psw.setCompoundDrawables(drawable1,null,null,null);

对应代码,psw是需要加图标的控件, R.drawable.chgpwd1是对应图标的图片。
drawable.setBounds(0,0,50,50);//第一0是距左边距离,第二0是距上边距离,50、50分别是长宽
psw.setCompoundDrawables(drawable,null,null,null); 分别左右上下放的图标,某个方向不放的时候,设置为null

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值