How to set property “android:drawableTop” of a button at runtime

前端 未结 8 1064
名媛妹妹
名媛妹妹 2020-12-04 21:01

How to set property \"android:drawableTop\" of a button at runtime

8条回答
  •  天涯浪人
    2020-12-04 21:32

    I use this code for use the "Theme.Holo" button with a "Custom image" at left and change it (the image)with a function that is called from various ways.

    protected void app_dibujarLogojuego() {
        if(bitmaplogojuego!=null){
            bitmaplogojuego.recycle();
            bitmaplogojuego=null;
        }
        Drawable LOGO = null;
        if(verjuego.equals("COSA1")){  LOGO = getResources().getDrawable(R.drawable.img_logo_COSA1);  }
        if(verjuego.equals("COSA2")){  LOGO = getResources().getDrawable(R.drawable.img_logo_COSA2);  }
        if(verjuego.equals("COSA3")){  LOGO = getResources().getDrawable(R.drawable.img_logo_COSA3);  }
        if(verjuego.equals("COSA4")){  LOGO = getResources().getDrawable(R.drawable.img_logo_COSA4);  }
    
        BUTTON_DECLARED_ID.setCompoundDrawablesWithIntrinsicBounds(LOGO, null , null, null);
    }
    

提交回复
热议问题