[Android] 動態更改ImageView的圖片來源

摘要:[Android] 動態更改ImageView的圖片來源


ImageView imageView1 = (ImageView) findViewById( R.id.imageView1);
        
String uri = "@drawable/" + 圖片名稱;
int imageResource = getResources().getIdentifier(uri, null, getPackageName());
Drawable image = getResources().getDrawable(imageResource);
imageView1.setImageDrawable(image);

 

參考網址: http://stackoverflow.com/questions/11737607/how-to-set-the-image-from-drawable-dynamically-in-android

 

 

--

不斷學習,精進自我

Herbert Fang