- 论坛徽章:
- 0
|
android控件
button
Java代码- 1.<Button
- 2. android:id="@+id/button"
- 3. android:layout_width="wrap_content"
- 4. android:layout_height="wrap_content"
- 5. android:text="普通按钮"
- 6. >
- 7. </Button>
- 8. <ImageButton
- 9. android:id="@+id/imageButton"
- 10. android:layout_width="wrap_content"
- 11. android:layout_height="wrap_content"
- 12. android:src="@drawable/img"
- 13. >
- 14. </ImageButton>
- 15. <ToggleButton
- 16. android:id="@+id/toggleButton"
- 17. android:layout_width="wrap_content"
- 18. android:layout_height="wrap_content"
- 19. >
- 20. </ToggleButton>
- <Button
- android:id="@+id/button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="普通按钮"
- >
- </Button>
- <ImageButton
- android:id="@+id/imageButton"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/img"
- >
- </ImageButton>
- <ToggleButton
- android:id="@+id/toggleButton"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- >
- </ToggleButton>
复制代码 监听事件
Java代码- 1.public void onClick(View v) {//重写的事件处理回调方法
- 2. if(v == button){//点击的是普通按钮
- 3. textView.setText("您点击的是普通按钮");
- 4. }
- 5. else if(v == imageButton){//点击的是图片按钮
- 6. textView.setText("您点击的是图片按钮");
- 7. }
- 8. else if(v == toggleButton){//点击的是开关按钮
- 9. textView.setText("您点击的是开关按钮");
- 10. }
- 11. }
复制代码 |
|