android.widget.ImageButton.setImageBitmap()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(152)

本文整理了Java中android.widget.ImageButton.setImageBitmap()方法的一些代码示例,展示了ImageButton.setImageBitmap()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ImageButton.setImageBitmap()方法的具体详情如下:
包路径:android.widget.ImageButton
类名称:ImageButton
方法名:setImageBitmap

ImageButton.setImageBitmap介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

myImageView.setOnTouchListener(new OnTouchListener()
 {

   @Override
   public boolean onTouch(View v, MotionEvent event)
   {
     ImageButton  imgbutton=(ImageButton)findViewById(R.id.imageButton1);
     Bitmap image = BitmapFactory.decodeResource(getResources(),R.drawable.image5);  
imgbutton.setImageBitmap(null);        
 imgbutton.setImageBitmap(image); 
     imgbutton.setVisibility(View.VISIBLE);
         return false;
   }   

});

代码示例来源:origin: stackoverflow.com

Bitmap image = BitmapFactory.decodeResource(getResources(),R.drawable.testbild);            

ImageButton btnMapLoc = (ImageButton) findViewById(R.id.imageButton1);        
LayoutParams lp = new LayoutParams(image.getWidth(), image.getHeight());
btnMapLoc.setLayoutParams(lp);

btnMapLoc.setImageBitmap(image);

代码示例来源:origin: xiaole0310/MyMusicPlayer

private void changeToPause(){
  play.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.pause));
}
/**

代码示例来源:origin: xiaole0310/MyMusicPlayer

private void changeToPlay(){
  play.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.play));
}
private void changeToPause(){

代码示例来源:origin: stackoverflow.com

a.setImageBitmap(BitmapFactory.decodeFile(picturePath));
b.setImageBitmap(BitmapFactory.decodeFile(picturePath));

代码示例来源:origin: appnexus/mobile-sdk-android

public void run() {
    Bitmap pbmp = BitmapFactory.decodeResource(adActivity.getResources(),
        android.R.drawable.ic_media_play);
    forward.setImageBitmap(pbmp);
    Matrix x = new Matrix();
    back.setScaleType(ImageView.ScaleType.MATRIX);
    x.postRotate(180.0f);
    Bitmap rotated = Bitmap.createBitmap(pbmp, 0, 0,
        pbmp.getWidth(), pbmp.getHeight(), x, true);
    back.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    forward.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    back.setImageBitmap(rotated);
  }
});

代码示例来源:origin: stackoverflow.com

public View getView(final int position, View convertView, ViewGroup parent){

  View MyView;
  ImageButton imageFolders;

  if(convertView==null){
    LayoutInflater li = ((Activity) MyContext).getLayoutInflater();
    MyView = li.inflate(R.layout.gallery_adapter, null);
   }else{
    MyView = convertView;
   }

   imageFolders = (ImageButton) MyView.findViewById(R.id.folder);

   try {
    imageFolders.setImageBitmap(bMap);
    imageFolders.setOnClickListener(this);
    imageFolders.setId(products.get(position).getId());
   } catch (Exception e) {}

   MyView.setLayoutParams(70, 70);
   return MyView;
}

代码示例来源:origin: stackoverflow.com

public View getView(final int position, View convertView, ViewGroup parent) {

  View MyView;

  if(convertView==null) 
  {
    // Inflate the layout
    LayoutInflater li = ((Activity) MyContext).getLayoutInflater();

    MyView = li.inflate(R.layout.gallery_adapter, null);
    ImageButton imageFolders = (ImageButton) MyView.findViewById(R.id.folder);

    try {

      imageFolders.setImageBitmap(bMap);
      imageFolders.setOnClickListener(this);
      imageFolders.setId(products.get(position).getId());
    } catch (Exception e) {

    }

    MyView.setLayoutParams(70, 70);
  }
  else
    MyView = convertView;
  return MyView;
}

代码示例来源:origin: xiaole0310/MyMusicPlayer

@Override
protected  void onResume(){
  super.onResume();
  //获得服务实例
  musicPlayerService=myApplication.musicPlayerService;
  if (musicPlayerService==null){
    play.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.play));
  }else if (musicPlayerService.mediaPlayer.isPlaying()){
    changSeekBar();
    play.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.pause));
  }else {
    changSeekBar();
    play.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.play));
  }
}

代码示例来源:origin: stackoverflow.com

File indexImage = new File(catList.get(1));
InputStream imageStream = new FileInputStream(indexImage);
Bitmap backgroundImage = null;
try {
  backgroundImage = BitmapFactory.decodeStream(imageStream);
}
catch(Exception e) {
  e.printStackTrace();
}
finally {
  try {
    //Dispose of the temporary resources
    imageStream.close();
    imageStream = null //So that the stream is deleted on next GC
  }
  catch(IOException e) {
    e.printStackTrace();
  }
}
if (backgroundImage != null) {
  ImageButton imgButton = new ImageButton(this);
  imgButton.setImageBitmap(backgroundImage);
  backgroundImage.recycle();
}

代码示例来源:origin: xiaole0310/MyMusicPlayer

public void playClick(){
  musicPlayerService=myApplication.musicPlayerService;
  if(musicPlayerService!=null){
    if(musicPlayerService.mediaPlayer.isPlaying()) {
      musicPlayerService.pause();
      play.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.mini_play));
      changeToPlay();
    }else {
      musicPlayerService.restart();
      play.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.mini_pause));
      changeToPause();
    }
  }
}

代码示例来源:origin: xiaole0310/MyMusicPlayer

public void playClick(){
  musicPlayerService=myApplication.musicPlayerService;
  if(musicPlayerService!=null){
    if(musicPlayerService.mediaPlayer.isPlaying()) {
      musicPlayerService.pause();
      play.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.mini_play));
      changeToPlay();
    }else {
      musicPlayerService.restart();
      play.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.mini_pause));
      changeToPause();
    }
  }
}

代码示例来源:origin: xiaole0310/MyMusicPlayer

public void playClick(){
  musicPlayerService=myApplication.musicPlayerService;
  if(musicPlayerService!=null){
    if(musicPlayerService.mediaPlayer.isPlaying()) {
      musicPlayerService.pause();
      play.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.mini_play));
      changeToPlay();
    }else {
      musicPlayerService.restart();
      play.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.mini_pause));
      changeToPause();
    }
  }
}

代码示例来源:origin: xiaole0310/MyMusicPlayer

public void playClick(){
  musicPlayerService=myApplication.musicPlayerService;
  if(musicPlayerService!=null){
    if(musicPlayerService.mediaPlayer.isPlaying()) {
      musicPlayerService.pause();
      play.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.mini_play));
      changeToPlay();
    }else {
      musicPlayerService.restart();
      play.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.mini_pause));
      changeToPause();
    }
  }
}

代码示例来源:origin: stackoverflow.com

for(int but=0; but<ClueList.size(); but++){
  ImageButton clueBut = new ImageButton(this);
   clueBut.setBackgroundResource(0);
   clueBut.setImageBitmap(ClueList.get(but).btmp);
   clueBut.setId(but);
   //clueBut.setOnClickListener(this);

   tr0.addView(clueBut);
}

代码示例来源:origin: stackoverflow.com

public View getView(int position, View convertView, ViewGroup parent) {
   if (convertView == null) { // if it's not recycled, initialize some
                 // attributes
     LayoutInflater li = (LayoutInflater) mContext
         .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     convertView = li.inflate(R.layout.icon_launcher, null);
   } 
   TextView tv = (TextView) convertView.findViewById(R.id.icon_text);
   ImageButton ib = (ImageButton) convertView.findViewById(R.id.icon_image);
   LinearLayout icon = (LinearLayout) convertView
           .findViewById(R.id.icon_launcher);
   // icon.setLayoutParams(new GridView.LayoutParams(203,200));
   ib.setScaleType(ib.getScaleType().FIT_XY);
   ib.setPadding(1, 1, 1, 1);
   ib.setFocusable(false);
   ib.setClickable(false);
   ib.setImageBitmap(BitmapFactory.decodeFile(mThumbIds.get(position)));
       tv.setText(mTextsIds.get(position));
   return convertView;
 }

代码示例来源:origin: AmaldevTA/ChipLayout

private ImageButton createImageButton(Context context) {
  final LayoutParams lparamsImageButton = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
  lparamsImageButton.gravity = Gravity.CENTER;
  lparamsImageButton.setMargins(0, 0, 0, 0);
  final ImageButton imageButton = new ImageButton(context);
  imageButton.setBackgroundColor(Color.parseColor("#00FFFFFF"));
  if(deleteIcon != null){
    imageButton.setImageBitmap(deleteIcon_);
  }else{
    imageButton.setImageResource(android.R.drawable.presence_offline);
  }
  imageButton.setLayoutParams(lparamsImageButton);
  imageButton.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View view) {
      View chip = (View) view.getParent();
      int pos = chipLayout.indexOfChild(chip);
      removeChipAt(pos);
    }
  });
  imageButton.setVisibility(View.GONE);
  return imageButton;
}

代码示例来源:origin: EggUncle/XposedNavigationBar

private static void initHomeNavbar(LinearLayout homeNavbar, final ViewPager vp) {
  XpLog.i("initHomeNavbar");
  Context context = homeNavbar.getContext();
  ImageButton btnCall = new ImageButton(context);
  btnCall.setBackgroundColor(Color.RED);
  btnCall.setImageBitmap(ImageUtil.byte2Bitmap(DataHook.mapImgRes.get(ConstantStr.FUNC_SMALL_POINT_CODE)));
  btnCall.setScaleType(ImageView.ScaleType.FIT_CENTER);
  //btnCall.setBackgroundColor(Color.alpha(255));
  LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
      ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  homeNavbar.addView(btnCall, params);
  setHomePointPosition(homeNavbar);
  btnCall.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
      vp.setCurrentItem(2);
    }
  });
}

代码示例来源:origin: souch/SMP

public boolean setDetails() {
    Bitmap albumBmp = null;
    RowSong rowSong = rows.getCurrSong();
    if (rowSong != null) {
      albumBmp = rowSong.getAlbumBmp(getApplicationContext(), coverArtNum);

      String title = rowSong.getTitle();
      songTitle.setText(title);

      songArtist.setText(rowSong.getArtist());

      String album = rowSong.getAlbum();
      if (rowSong.getYear() > 1000)
        album += " - " + rowSong.getYear();
      songAlbum.setText(album);
    }
    if (albumBmp != null) {
      albumImage.setImageBitmap(albumBmp);
//            albumImage.setVisibility(View.VISIBLE);
    } else {
      albumImage.setImageResource(R.drawable.ic_default_coverart);
//            albumImage.setVisibility(View.GONE);
    }

    return albumBmp != null;
  }

代码示例来源:origin: stackoverflow.com

TableLayout sv = (TableLayout) findViewById(R.id.categoryLinearLayout1);

for (int i = 0; i < 5; i++) {
  TableRow tr = new TableRow(this);
  tr.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
  for (int j = 0; j < 2; j++) {
     ImageButton ib = new ImageButton(this);
     // ib.setImageDrawable(getResources().getDrawable(R.drawable.cat1));
     Bitmap bmp = BitmapFactory.decodeResource(getResources(),
       R.drawable.cat1);
     int width = 300;
     int height = 300;
     Bitmap resizedbitmap = Bitmap.createScaledBitmap(bmp, width,
      height, true);
     ib.setImageBitmap(resizedbitmap);
     ib.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
     tr.addView(ib);
   }
   sv.add(tr); 
}

相关文章

ImageButton类方法