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

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

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

ImageButton.setBackgroundColor介绍

暂无

代码示例

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

ImageButton theButton = (ImageButton )findViewById(R.id.theButton);
theButton.setVisibility(View.VISIBLE);
theButton.setBackgroundColor(Color.TRANSPARENT);

theButton.setOnClickListener(new OnClickListener()
{   
 @Override
 public void onClick(View v)
 {
  // DO STUFF
 }
 });

代码示例来源:origin: saki4510t/libcommon

@Override
  public void run() {
    if ((colors != null) && (colors.length >= 8)) {
      for (int i = 0; i < 8; i++) {
        final int id = COLOR_BTN_IDS[i];
        final ImageButton button = findViewById(id);
        if (button != null) {
          button.setBackgroundColor(colors[i]);
        }
      }
    }
  }
});

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

@Override
public View getView(int position, View convertView, ViewGroup parent) {
  ImageButton image;
  if (convertView == null) {
    LayoutInflater mInflater = (LayoutInflater) getContext()
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    convertView  = mInflater.inflate(R.layout.grid__item, null);
  }

  image = (ImageButton)  convertView.findViewById(R.id.image);
  image.setImageResource(Constantes.HIDECARD_RESOURCE);
  image.setLayoutParams(new GridView.LayoutParams(130, 130));
  image.setBackgroundColor(Color.TRANSPARENT);
  return convertView;
}

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

public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   LinearLayout btnLO = new LinearLayout(this);    
   btnLO.setOrientation(LinearLayout.VERTICAL);
   ImageButton i1 = new ImageButton(this);
   i1.setBackgroundColor(color.background_dark);
   i1.setImageDrawable(getResources().getDrawable(R.drawable.rana));   
   btnLO.addView(i1, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));                      
//    btnLO.setGravity(Gravity.LEFT | Gravity.CENTER_HORIZONTAL);     
   this.addContentView(btnLO, new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); 
 }

代码示例来源:origin: jamorham/xDrip-plus

final int onColor = Color.RED;
insulintabbutton.setBackgroundColor(offColor);
carbstabbutton.setBackgroundColor(offColor);
timetabbutton.setBackgroundColor(offColor);
bloodtesttabbutton.setBackgroundColor(offColor);
switch (currenttab) {
  case "insulin":
    insulintabbutton.setBackgroundColor(onColor);
    append = " units";
    break;
  case "carbs":
    carbstabbutton.setBackgroundColor(onColor);
    append = " carbs";
    break;
  case "bloodtest":
    bloodtesttabbutton.setBackgroundColor(onColor);
    append = " BG";  // TODO get mgdl or mmol here
    break;
  case "time":
    timetabbutton.setBackgroundColor(onColor);
    append = " time";
    break;

代码示例来源:origin: JBossOutreach/lead-management-android

@Override
  public boolean onLongClick(View view) {
    final int newVisibility = deleteButton.getVisibility() == View.VISIBLE
        ? View.GONE
        : View.VISIBLE;
    deleteButton.setVisibility(newVisibility);
    if(mPref.getBoolean(PREF_DARK_THEME,false)){
      deleteButton.setBackgroundColor(Color.parseColor("#303030"));
      deleteButton.setImageDrawable(mContext.getResources().getDrawable(R.drawable.ic_close_white));
    }
    return true;
  }
}

代码示例来源:origin: WomenWhoCode/WomenWhoCode

private void setColorFilter() {
  if (!TextUtils.isEmpty(etMessage.getText())) {
    btnSend.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.teal));
    btnSend.setPadding(10, 4, 10, 4);
  } else {
    btnSend.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.lightestGray));
    btnSend.setPadding(10, 4, 10, 4);
  }
}

代码示例来源:origin: scoutant/blokish

private ImageButton button(int src, OnClickListener l, int position) {
  ImageButton btn = new ImageButton(context);
  LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL);
  int margin = Math.min( (width - 3*128)/3, 80);
  params.leftMargin = margin;
  params.rightMargin = margin;
  if (position==0) params.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;
  if (position==1) params.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
  btn.setLayoutParams(params);
  btn.setImageDrawable(context.getResources().getDrawable(src));
  btn.setScaleType(ScaleType.CENTER_INSIDE);
  btn.setBackgroundColor(Color.TRANSPARENT);
  btn.setOnClickListener(l);
  return btn;
  
}

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

public static ImageButton createCloseButton(Context context, boolean custom_close) {
  final ImageButton close = new ImageButton(context);
  if (!custom_close){
    close.setImageDrawable(context.getResources().getDrawable(
        android.R.drawable.ic_menu_close_clear_cancel));
  }
  FrameLayout.LayoutParams blp = new FrameLayout.LayoutParams(
      FrameLayout.LayoutParams.WRAP_CONTENT,
      FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.RIGHT
      | Gravity.TOP);
  close.setLayoutParams(blp);
  close.setBackgroundColor(Color.TRANSPARENT);
  return close;
}

代码示例来源:origin: NightscoutFoundation/xDrip

final int onColor = Color.RED;
insulintabbutton.setBackgroundColor(offColor);
carbstabbutton.setBackgroundColor(offColor);
timetabbutton.setBackgroundColor(offColor);
bloodtesttabbutton.setBackgroundColor(offColor);
switch (currenttab) {
  case "insulin":
    insulintabbutton.setBackgroundColor(onColor);
    append = " " + getString(R.string.units);
    break;
  case "carbs":
    carbstabbutton.setBackgroundColor(onColor);
    append = " " + getString(R.string.carbs);
    break;
  case "bloodtest":
    bloodtesttabbutton.setBackgroundColor(onColor);
    append = " " + bgUnits;
    break;
  case "time":
    timetabbutton.setBackgroundColor(onColor);
    append = " " + getString(R.string.when);
    break;

代码示例来源:origin: jamorham/xDrip-plus

final int onColor = Color.RED;
insulintabbutton.setBackgroundColor(offColor);
carbstabbutton.setBackgroundColor(offColor);
timetabbutton.setBackgroundColor(offColor);
bloodtesttabbutton.setBackgroundColor(offColor);
switch (currenttab) {
  case "insulin":
    insulintabbutton.setBackgroundColor(onColor);
    append = " " + getString(R.string.units);
    break;
  case "carbs":
    carbstabbutton.setBackgroundColor(onColor);
    append = " " + getString(R.string.carbs);
    break;
  case "bloodtest":
    bloodtesttabbutton.setBackgroundColor(onColor);
    append = " " + bgUnits;
    break;
  case "time":
    timetabbutton.setBackgroundColor(onColor);
    append = " " + getString(R.string.when);
    break;

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

private void setupBalloon(ImageButton b, int i) {
  int imageId = (int)(Math.random() * images.length);
  LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
      LinearLayout.LayoutParams.WRAP_CONTENT);
  b.setLayoutParams(params);
  b.setImageResource(images[imageId]);
  b.setBackgroundColor(Color.TRANSPARENT);
  b.setScaleX(0.4f);
  b.setScaleY(0.4f);
  b.setX((float) (Math.random() * (width - b.getWidth())));
  b.setY((float) (Math.random() * (height - b.getHeight())));
  b.setVisibility(View.VISIBLE);
}

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

private void addCloseButton(FrameLayout layout) {
  if ((adView != null) && adView.getAdType() == AdType.VIDEO) {
    return;
  }
  final ImageButton close = new ImageButton(context);
  close.setImageDrawable(context.getResources().getDrawable(
      android.R.drawable.ic_menu_close_clear_cancel));
  FrameLayout.LayoutParams blp = new FrameLayout.LayoutParams(
      FrameLayout.LayoutParams.WRAP_CONTENT,
      FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.RIGHT
      | Gravity.TOP);
  close.setLayoutParams(blp);
  close.setBackgroundColor(Color.TRANSPARENT);
  close.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      onHideCustomView();
    }
  });
  layout.addView(close);
}

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

RelativeLayout rl = new RelativeLayout(this);
ImageButton btnBar = new ImageButton(this);

RelativeLayout.LayoutParams btnParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, 80);

btnParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

btnBar.setLayoutParams(btnParams);
btnBar.setBackgroundColor(Color.RED); // test with red background

TranslateAnimation a = new TranslateAnimation(
              Animation.RELATIVE_TO_PARENT, 0,
              Animation.RELATIVE_TO_PARENT, 0,
              Animation.RELATIVE_TO_PARENT, (float)100, 
              Animation.RELATIVE_TO_PARENT, (float)0);

a.setDuration(1000);
btnBar.startAnimation(a); // add animation while start

rl.addView(btnBar);
setContentView(rl);

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

btnBack.setImageBitmap(backBitmap);
btnBack.setScaleType(ImageView.ScaleType.FIT_CENTER);
btnBack.setBackgroundColor(Color.alpha(255));
btnFunc.setImageBitmap(funcBitmap);
btnFunc.setScaleType(ImageView.ScaleType.FIT_CENTER);
btnFunc.setBackgroundColor(Color.alpha(255));

代码示例来源:origin: wuhenzhizao/android-titlebar

btnRight.setId(StatusBarUtils.generateViewId());
btnRight.setImageResource(rightImageResource);
btnRight.setBackgroundColor(Color.TRANSPARENT);
btnRight.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
btnRight.setPadding(PADDING_12, 0, PADDING_12, 0);

代码示例来源: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: lime-ime/limeime

public void initViews() {
  if (DEBUG)
    Log.i(TAG, "initViews()");
  if (mCandidateView == null) {
    mButtonRightExpand = findViewById(R.id.candidate_right_parent);
    mRightButton = (ImageButton) findViewById(R.id.candidate_right);
    if (mRightButton != null) {
      mRightButton.setOnClickListener(this);
    }
    mCandidateView = (CandidateView) findViewById(R.id.candidatesView);
    mCandidateView.setBackgroundColor(mCandidateView.mColorBackground);
    mRightButton.setBackgroundColor(mCandidateView.mColorBackground);
    this.setBackgroundColor(mCandidateView.mColorBackground);
  }
}

代码示例来源:origin: lime-ime/limeime

public void initViews() {
  if (mCandidateView == null) {
    mButtonExpandLayout = findViewById(R.id.candidate_right_parent);
    mButtonExpand = (ImageButton) findViewById(R.id.candidate_right);
    if (mButtonExpand != null) {
      mButtonExpand.setOnTouchListener(this);
    }
    mCandidateView = (CandidateView) findViewById(R.id.candidates);
    TextView mEmbeddedTextView = (TextView) findViewById(R.id.embeddedComposing);
    mCandidateView.setEmbeddedComposingView(mEmbeddedTextView);
    mCandidateView.setBackgroundColor(mCandidateView.mColorBackground);
    mButtonExpand.setBackgroundColor(mCandidateView.mColorBackground);
    mButtonExpand.setImageDrawable(mCandidateView.mDrawableExpandButton);
  }
}

相关文章

ImageButton类方法