1//this for xml file
2<Button
3 android:id="@+id/button"
4 android:layout_width="wrap_content"
5 android:layout_height="wrap_content"
6 android:layout_centerHorizontal="true"
7 android:layout_marginTop="109dp"
8 android:text="hello"
9 />
10
11//this for java file
12Button btn;
13 @Override
14 protected void onCreate(Bundle savedInstanceState) {
15 super.onCreate(savedInstanceState);
16 setContentView(R.layout.activity_main);
17 btn = (Button) findViewById(R.id.button);
18 btn.setOnClickListener(new View.OnClickListener() {
19 @Override
20 public void onClick(View view) {
21 //do something
22 }
23 });
24 }
1mycodes_Button.setOnTouchListener(new OnTouchListener() {
2 @Override
3 public boolean onTouch(View v, MotionEvent event) {
4 mycodes_Button.setPressed(true);
5 return true;
6 }
7});
8