implement android:src=“@drawable/image” programmatically in Android

前端 未结 6 1127
广开言路
广开言路 2021-02-03 18:24

I am trying to set the foreground image on an image button. After some research, I came across this code sample:



        
6条回答
  •  旧巷少年郎
    2021-02-03 19:16

    try this::

    ImageButton tran_btn_skip;
    
    tran_btn_skip = (ImageButton) findViewById(R.id.btn);
        try {
            Bitmap bitmap_skip = BitmapFactory.decodeStream((InputStream) new URL(
                    "http://233.129.115.55/MRESC/images/test/skip.png")
                    .getContent());
            tran_btn_skip.setImageBitmap(bitmap_skip);
        } catch (Exception e) {
        }
    

提交回复
热议问题