1 选择 imagebutton
2 在imagedraw下面放张图tu1.jpg
3主代码如下
import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.ImageButton; import android.widget.TextView; public class MainActivity extends AppCompatActivity { private ImageButton imgbt = null; private TextView textx = null; private TextView texty = null; private TextView textz = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imgbt = (ImageButton) findViewById(R.id.imageButton); textx = (TextView) findViewById(R.id.editText); texty = (TextView) findViewById(R.id.editText2); textz = (TextView) findViewById(R.id.editText3); imgbt.setImageDrawable(getResources().getDrawable(R.drawable.tu1)); imgbt.setOnClickListener(listener); } private View.OnClickListener listener = new View.OnClickListener() { public void onClick(View v) { if (v == imgbt) { double m_x,m_y,m_z; m_x= Double.parseDouble(textx.getText().toString()); m_y= Double.parseDouble(texty.getText().toString()); m_z = m_x+m_y; textz.setText(String.valueOf(m_z)); } } }; }