2
public class AccountSetupActivity extends Activity implements OnClickListener {
    ImageButton fbButton;

    @Override
    public void onClick(View v) {
        Toast.makeText(this, "FB clicked", Toast.LENGTH_SHORT).show();
        Drawable fbLight = getResources().getDrawable(R.drawable.fborange);
        fbButton.setBackgroundDrawable(fbLight);
        // fbButton.setBackgroundResource(0);
    }

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.setupaccounts);
        fbButton = (ImageButton) findViewById(R.id.fbButton);
        fbButton.setOnClickListener(this);

    }

}
4

3 回答 3

1

试试这条线来设置图像:

        fbButton.setImageDrawable(fbLight);

我认为您打算设置最前面的图像,但正在设置背景图像

于 2012-12-03T10:29:59.380 回答
0

试试这个:

fbButton.setImageResource(R.drawable.fborange)

于 2012-12-03T12:47:52.240 回答
0

尝试这个

 buttonName.setBackgroundResource(R.drawable.imageName);
于 2012-12-03T10:08:17.637 回答