2013-07-12 2 views
4

URL에서 이미지를 다운로드하고이를 런타임시 내 액션 바의 홈 아이콘으로 설정하고 싶습니다. 그것을 수행하는 AsyncTask를 사용하고 있지만 변경하지 않는 것 같습니다. 어떤 아이디어?url에서 비트 맵을 android로 작업 표시 줄 홈 아이콘으로 설정

class getProfilePicture extends AsyncTask<Void, Void, Void> { 

     protected Void doInBackground(Void... params) { 
      try { 
       URL url; 
       url = new URL("http://www.i2clipart.com/cliparts/2/a/3/2/clipart-fcrc-logo-handshake-2a32.png"); 
       HttpURLConnection conn = (HttpURLConnection) url 
         .openConnection(); 
       conn.setDoInput(true); 
       conn.connect(); 
       InputStream is = conn.getInputStream(); 
       image = BitmapFactory.decodeStream(is); 

      } catch (MalformedURLException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
      return null; 

     } 

    protected void onPostExecute() { 
     // TODO: check this.exception 
     Resources res = getResources(); 
     BitmapDrawable icon = new BitmapDrawable(res, image); 
     getSupportActionBar().setIcon(icon); 
     //getSupportActionBar().setLogo(icon); 
     } 
    } 

답변

0

이 코 틀린 코드

Glide.with(this).load(imageUrl).asBitmap().into(object : SimpleTarget<Bitmap>() { 
        override fun onResourceReady(resource: Bitmap?, glideAnimation: GlideAnimation<in Bitmap>?) { 
         val drawable = BitmapDrawable(resources, resource) 
         supportActionBar?.setIcon(drawable) 
        } 
       }) 
을 시도 할 수 있습니다
관련 문제