Android Button with text and image

前端 未结 4 1232
温柔的废话
温柔的废话 2021-01-21 10:04

After seeing many questions for this feature and attempting to follow the answers, I was left wondering if there was a clearer example to be had?

Edit: I was attempting

4条回答
  •  情深已故
    2021-01-21 10:35

    Try this:

    Drawable appImg = getApplicationContext().getResources().getDrawable( R.drawable.ic_launcher );
    appImg.setBounds( 0, 0, appImg.getIntrinsicHeight(), appImg.getIntrinsicWidth() );
    
    Button btn_ok = (Button) findViewById(R.id.ok);
    btn_ok.setCompoundDrawables( null, null, appImg, null );
    

    Hope it helps you.

    Thanks.

提交回复
热议问题