本文整理了Java中android.widget.ImageButton.setBackground()
方法的一些代码示例,展示了ImageButton.setBackground()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ImageButton.setBackground()
方法的具体详情如下:
包路径:android.widget.ImageButton
类名称:ImageButton
方法名:setBackground
暂无
代码示例来源:origin: rockerhieu/emojicon
private void addTabIcon(EmojiconPage page, int index) {
ImageButton icon = new ImageButton(getContext());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT);
params.weight = 1;
icon.setBackground(null);
icon.setScaleType(ImageView.ScaleType.CENTER);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
icon.setImageDrawable(getContext().getResources().getDrawable(page.getIcon()));
} else {
icon.setImageDrawable(getContext().getDrawable(page.getIcon()));
}
mTabsContainer.addView(icon, mTabsContainer.getChildCount() - 2, params);
mTabs[index] = icon;
final int indexToMove = index;
icon.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mViewPager.setCurrentItem(indexToMove, true);
}
});
}
代码示例来源:origin: stackoverflow.com
mMainMenuButton.setBackground(null);
mMainMenuButton.setImageDrawable(menuIcon);
mMainMenuButton.setOnClickListener(new View.OnClickListener() {
代码示例来源:origin: xiaole0310/MyMusicPlayer
public void changeToPlay(){
play.setBackground(this.getResources().getDrawable(R.drawable.mini_play));
}
public void changeToPause(){
代码示例来源:origin: xiaole0310/MyMusicPlayer
public void changeToPlay(){
play.setBackground(this.getResources().getDrawable(R.drawable.mini_play));
}
public void changeToPause(){
代码示例来源:origin: xiaole0310/MyMusicPlayer
public void changeToPause(){
play.setBackground(this.getResources().getDrawable(R.drawable.mini_pause));
}
public void setView(){
代码示例来源:origin: xiaole0310/MyMusicPlayer
public void changeToPlay(){
play.setBackground(this.getResources().getDrawable(R.drawable.mini_play));
}
public void changeToPause(){
代码示例来源:origin: xiaole0310/MyMusicPlayer
public void changeToPause(){
play.setBackground(this.getResources().getDrawable(R.drawable.mini_pause));
}
public void setView(){
代码示例来源:origin: xiaole0310/MyMusicPlayer
public void changeToPlay(){
play.setBackground(this.getResources().getDrawable(R.drawable.mini_play));
}
public void changeToPause(){
代码示例来源:origin: xiaole0310/MyMusicPlayer
public void changeToPlay(){
play.setBackground(this.getResources().getDrawable(R.drawable.mini_play));
}
public void changeToPause(){
代码示例来源:origin: xiaole0310/MyMusicPlayer
public void changeToPause(){
play.setBackground(this.getResources().getDrawable(R.drawable.mini_pause));
}
代码示例来源:origin: xiaole0310/MyMusicPlayer
public void changeToPause(){
play.setBackground(this.getResources().getDrawable(R.drawable.mini_pause));
}
代码示例来源:origin: xiaole0310/MyMusicPlayer
public void changeToPause(){
play.setBackground(this.getResources().getDrawable(R.drawable.mini_pause));
}
代码示例来源:origin: stackoverflow.com
private View createImageButton(int x, int y) {
ImageButton button = new ImageButton(context);
// Adjust button size (?)
button.setLayoutParams(new TableRow.LayoutParams(myImage.getMinimumWidth(),
myImage.getMinimumHeight(), 1f));
//It doesn't work at all
button.setBackground(myImage);
button.setScaleType(ScaleType.FIT_XY)
...
return button;
}
代码示例来源:origin: stackoverflow.com
public class MainActivity extends AppCompatActivity {
private ImageButton img;
private boolean isSelected = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img = (ImageButton) findViewById(R.id.img);
img.setClickable(true);
img.setBackground(getDrawable(R.drawable.unselected_circle));
img.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
img.startAnimation(AnimationUtils.loadAnimation(getBaseContext(), android.R.anim.fade_in));
if (isSelected) {
isSelected = false;
img.setBackground(getDrawable(R.drawable.unselected_circle));
} else {
isSelected = true;
img.setBackground(getDrawable(R.drawable.selected_circle));
}
}
});
}
代码示例来源:origin: stackoverflow.com
final LinearLayout lm = (LinearLayout) findViewById(R.id.linearMain);
RelativeLayout rl = new RelativeLayout(this);
ImageView cb1 = new ImageView(this);
cb1.setId(1);
cb1.setImageResource(R.drawable.ic_launcher);
ImageButton cb2 = new ImageButton(this);
cb2.setImageResource(R.drawable.ic_launcher);
cb2.setBackground(null);
cb2.setId(2);
LayoutParams rp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
rp.addRule(RelativeLayout.BELOW, cb1.getId());
cb2.setLayoutParams(rp);
rl.addView(cb1);
rl.addView(cb2);
lm.addView(rl);
代码示例来源:origin: posm/OpenMapKitAndroid
@Override
public void onClick(View v) {
boolean userLocationIsEnabled = mapView.getUserLocationEnabled();
if (userLocationIsEnabled) {
mapView.setUserLocationEnabled(false);
locationButton.setBackground(getResources().getDrawable(R.drawable.roundedbutton));
} else {
mapView.setUserLocationEnabled(true);
mapView.goToUserLocation(true);
locationButton.setBackground(getResources().getDrawable(R.drawable.roundedbutton_blue));
}
}
});
代码示例来源:origin: stackoverflow.com
img.setBackground(unselected);
img.setOnClickListener(new View.OnClickListener() {
@Override
if (isSelected) {
isSelected = false;
img.setBackground(unselected);
} else {
isSelected = true;
img.setBackground(selected);
代码示例来源:origin: posm/OpenMapKitAndroid
private void toggleMoveNodeMode() {
final ImageButton moveNodeModeBtn = (ImageButton)findViewById(R.id.moveNodeModeBtn);
final ImageButton moveNodeMarkerBtn = (ImageButton)findViewById(R.id.moveNodeMarkerBtn);
final Button moveNodeBtn = (Button)findViewById(R.id.moveNodeBtn);
if (moveNodeMode) {
moveNodeMarkerBtn.setVisibility(View.GONE);
moveNodeBtn.setVisibility(View.GONE);
moveNodeModeBtn.setBackground(getResources().getDrawable(R.drawable.roundedbutton));
showSelectedMarker();
} else {
moveNodeMarkerBtn.setVisibility(View.VISIBLE);
moveNodeBtn.setVisibility(View.VISIBLE);
moveNodeModeBtn.setBackground(getResources().getDrawable(R.drawable.roundedbutton_orange));
hideSelectedMarker();
proportionMapAndList(100, 0);
}
moveNodeMode = !moveNodeMode;
}
代码示例来源:origin: huangfangyi/YiChat
tabs[i] = tableLayout.getTabAt(i);
ImageButton imageView=new ImageButton(getContext());
imageView.setBackground(null);
imageView.setImageResource(R.drawable.dot_emoji);
tabs[i].setCustomView(imageView);
代码示例来源:origin: wasdennnoch/AndroidN-ify
@Override
public void handleLayoutInflated(LayoutInflatedParam liparam) throws Throwable {
ImageButton action = (ImageButton) liparam.view;
Context context = action.getContext();
ResourceUtils res = ResourceUtils.getInstance(context);
int width_height = res.getDimensionPixelSize(R.dimen.notification_media_action_width);
int padding = ResourceUtils.getInstance(context).getDimensionPixelSize(R.dimen.notification_media_action_padding);
LinearLayout.LayoutParams lParams = new LinearLayout.LayoutParams(width_height, width_height);
lParams.setMarginEnd(res.getDimensionPixelSize(R.dimen.notification_media_action_margin));
lParams.setMargins(0, 0, res.getDimensionPixelSize(R.dimen.notification_media_action_margin), 0);
action.setLayoutParams(lParams);
action.setPadding(padding, padding, padding, padding);
action.setBackground(res.getDrawable(R.drawable.notification_material_media_action_background));
}
});
内容来源于网络,如有侵权,请联系作者删除!