java.awt.Button.setBackground()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(136)

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

Button.setBackground介绍

暂无

代码示例

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

final Drawable positiveButtonDrawable = getResources().getDrawable(R.drawable.alert_dialog_button_light_green);
if (Build.VERSION.SDK_INT >= 16) {
 negativeButton.setBackground(negativeButtonDrawable);
 positiveButton.setBackground(positiveButtonDrawable);
} else {
 negativeButton.setBackgroundDrawable(negativeButtonDrawable);

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

Button button = (Button) findViewById(R.id.camButton);      
if(camPressed){
  button.setBackground(getResources().getDrawable(R.drawable.cam_pressed))
 } else{
   //other stuff
 }

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

...
Button brownieButton = (Button)findViewById(R.id.myBrownieButton);
switch (brownieType) {  // brownieType would be an int indicating which State List is needed
case 0:
  brownieButton.setBackground(getResources().getDrawable(R.id.brownie_selector0));
  break;
case 1:
  brownieButton.setBackground(getResources().getDrawable(R.id.brownie_selector1));
  break;
...
}

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

public void setIcontoButton(Button targetButton, Drawable icon)
{
  int sdk = android.os.Build.VERSION.SDK_INT;
  if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
    targetButton.setBackgroundDrawable(icon)
  } else {
    targetButton.setBackground(icon);
  }

}

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

mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
     @Override
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Button b = (Button) view.findViewById(R.id.buttonPlay);
   b.setBackground(c.getResources().getDrawable(R.drawable.ic_action_play));
   your_adapter.notifyDataSetChanged();
     }
   });

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

public static void setBacground(Button buttonA, Drawable draw) {
  int sdk = android.os.Build.VERSION.SDK_INT;
  if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
    buttonA.setBackgroundDrawable( draw);
  } else {
    buttonA.setBackground( draw);
  }
}

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

// assuming "mainMenuButtons" (or whatever) contains your first four objects
// note I don't know what color (84, 209, 241) actually is
for(Button btn : mainMenuButtons) {
  btn.setBackground(new java.awt.Color(84, 209, 241));
}

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

Button bProfile; // your Button
Bitmap bitmap; // your bitmap

if(android.os.Build.VERSION.SDK_INT < 16) {
  bProfile.setBackgroundDrawable(new BitmapDrawable(getResources(), bitmap));
}
else {
  bProfile.setBackground(new BitmapDrawable(getResources(),bitmap));
}

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

public void Favorites(View V) {
Button star = (Button) findViewById(R.id.buttonStar);

if(star.getBackground().getConstantState().equals(getResources().getDrawable(R.drawable.btn_star_off).getConstantState())) 
  {
      star.setBackground(R.drawable.btn_star_on);
  } else {               
      star.setBackground(R.drawable.btn_star_off);
 }
}

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

Button bProfile; // your Button
Bitmap bitmap; // your bitmap

if(android.os.Build.VERSION.SDK_INT < 16) {
  bProfile.setBackgroundDrawable(new BitmapDrawable(getResources(), bitmap));
}
else {
  bProfile.setBackground(new BitmapDrawable(getResources(),bitmap));
}

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

Button b = (Button) findViewById(R.id.button);

if (b instanceof AppCompatButton) {
  ((AppCompatButton)b).setSupportBackgroundTintList(null);
}

Drawable d = b.getBackground();
d = DrawableCompat.wrap(d);
DrawableCompat.setTintList(d, getResources().getColorStateList(...));
b.setBackground(d); // or setBackgroundDrawable on older platforms

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

Button b = (Button) findViewById(R.id.button);
Drawable d = b.getBackground();
d = DrawableCompat.wrap(d);
DrawableCompat.setTintList(d, getResources().getColorStateList(...));
b.setBackground(d); // or setBackgroundDrawable on older platforms

代码示例来源:origin: davidsoergel/jlibsvm

public void actionPerformed(ActionEvent e)
  {
  button_change_clicked();
  button_change.setBackground(colors[current_value]);
  }
});

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

final Iterator<Button> buttonI = buttons.iterator();
final Iterator<Territory> territoryI = territories.iterator();
while (territoryI.hasNext() && buttonI.hasNext()) {
  final Button button = buttonI.next();
  final Territory territory = territoryI.next();
  button.setBackground(territory.getOwner().getColor());
  button.setLabel(territory.units());
}

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

Button button = new Button(getContext());
Bitmap backgroundBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.my_button);
BitmapDrawable backgroundDrawable = new BitmapDrawable(getResources(), backgroundBitmap);
backgroundDrawable.setGravity(Gravity.CENTER); // also LEFT, CENTER_VERTICAL, etc.
backgroundDrawable.setColorFilter(new PorterDuffColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP));
button.setBackground(backgroundDrawable);

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

Button button = new Button(null, imageView);

// quadratic grey background
button.setBackground(new Background(new BackgroundFill(Color.GREY, CornerRadii.EMPTY, Insets.EMPTY)));

// no padding
button.setPadding(Insets.EMPTY);

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

StateListDrawable content = new StateListDrawable();
Drawable pressedDrawable = new BitmapDrawable(getResources(),bitmap);
//Your other drawables (focused, .....)

content.addState(new int[] { android.R.attr.state_pressed }, pressedDrawable);
//Add the other drawables the same way

Button button = (Button) view.findViewById(R.id.my_button);
button.setBackground(content);

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

private void configDot(Button b, int size, int margin){
  b.setBackground(getResources().getDrawable(R.drawable.roundbutton));
  LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(getPxFromDp(size), getPxFromDp(size));
  p.gravity = Gravity.CENTER_HORIZONTAL;
  p.setMargins(0, margin, 0, margin);
  b.setLayoutParams(p);
}
private int getPxFromDp(int dp){
  return (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics());
}

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

MyDrawable drawable = new MyDrawable(...);
MyDrawable drawablePressed = new MyDrawable(...);
MyDrawable drawableFocused = new MyDrawable(...);

StateListDrawable stateDrawable = new StateListDrawable();
stateDrawable.addState(new int[]{android.R.attr.state_pressed}, drawablePressed);
stateDrawable.addState(new int[]{android.R.attr.state_focused}, drawableFocused);
stateDrawable.addState(new int[]{}, drawable);

Button button = (Button) findViewById(R.id.button);
button.setBackground(stateDrawable);

代码示例来源:origin: IanDarwin/javasrc

public void init() {
    setBackground(Color.cyan);        // see Graphics chapter.
    Panel p = new Panel();
    p.setBackground(Color.red);
    p.add(applyB = new Button("Apply"));
    applyB.setBackground(Color.white);
    p.add(exitB = new Button("Exit"));
    exitB.setForeground(Color.red);
    add(p);  // add (connect) "p" to "this", the Applet
  }
}

相关文章