Programmatically change drawableLeft of Button

后端 未结 5 1234
太阳男子
太阳男子 2021-02-09 00:50

I\'m using a Button

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-09 01:36

    To do this, you can use the

    setCompoundDrawables(...);

    method. Be aware that comes with TextView, not Button.

    This is how to use it:

    Drawable img = getContext().getResources().getDrawable( R.drawable.yourimage);
    img.setBounds( 0, 0, 60, 60 );  // set the image size
    txtVw.setCompoundDrawables( img, null, null, null );
    

    Taken from: How to programmatically set drawableLeft on Android button?

提交回复
热议问题