Android Stdio实现点击按钮出现图片

 

    
public class MainActivity extends AppCompatActivity {
    private ImageView imageView = null;
    private Button bt1 = null;//图1
    private Button bt2 = null;//图2

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        imageView = (ImageView) findViewById(R.id.photo);
        bt1 = (Button) findViewById(R.id.button_1);
        bt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(v==bt1){
                    imageView.setImageResource( R.drawable.face2);
                }
            }
        });
        bt2 = (Button) findViewById(R.id.button_2);
        bt2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (v==bt2){
                    imageView.setImageResource( R.drawable.wanglibo);

                }
            }
        });
    }

 

 

你可能感兴趣的