Android7.0中文文档(API) --- Button
来源:互联网 发布:淘宝规定多长时间发货 编辑:程序博客网 时间:2024/05/20 23:59
完整内容,请查看:http://www.zhdoc.net/android/reference/android/widget/Button.html
Button
public class Button
extendsTextView
Represents a push-button widget. Push-buttons can be pressed, or clicked, by the user to perform an action.
按钮控件。按钮由用户执行一个操作,它可以被按下,或点击。
A typical use of a push-button in an activity would be the following:
在activity中使用按钮的通常用法如下:
public class MyActivity extends Activity { protected void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.content_layout_id); final Button button = (Button) findViewById(R.id.button_id); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click } }); } }
However, instead of applying an OnClickListener
to the button in your activity, you can assign a method to your button in the XML layout, using the android:onClick
attribute. For example:
但是,你可以在XML布局中使用android:onClick
属性,将一个方法赋值给按钮,而不是用OnClickListener
来响应你activity中的按钮的操作。例如:
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/self_destruct" android:onClick="selfDestruct" />
Now, when a user clicks the button, the Android system calls the activity's selfDestruct(View)
method. In order for this to work, the method must be public and accept aView
as its only parameter. For example:
现在,当用户点击按钮时,Android系统将调用activity的selfDestruct(View)
的方法。为使其能够工作,这个方法必须是public的,并且仅接受一个View
类型的参数。例如:
public void selfDestruct(View view) { // Kabloey }
The View
passed into the method is a reference to the widget that was clicked.
传入到此方法的View
参数,将是被点击的控件的对象。
按钮样式
Every Button is styled using the system's default button background, which is often different from one device to another and from one version of the platform to another. If you're not satisfied with the default button style and want to customize it to match the design of your application, then you can replace the button's background image with astate list drawable. A state list drawable is a drawable resource defined in XML that changes its image based on the current state of the button. Once you've defined a state list drawable in XML, you can apply it to your Button with theandroid:background
attribute. For more information and an example, seeState List Drawable.
每个按钮都是使用系统默认的按钮背景,因此不同的设备上的不同平台版本,将出现不同的效果。如果你对默认的按钮样式不满意,并且想要定制它来匹配你的应用程序的设计,那么你可以使用一个状态列表drawable来替换按钮的背景图像。状态列表drawable是定义在XML中的一个drawable的资源,其根据按钮的当前状态来更改图像。一旦你已经在XML中定义了一个状态列表drawable,则你可以将它赋值给按钮的android:background
属性。更多的信息和示例,请参考状态列表drawable。
See the Buttons guide.
请参考Buttons。
XML attributes
XML属性
完整内容,请查看:http://www.zhdoc.net/android/reference/android/widget/Button.html
- Android7.0中文文档(API) --- Button
- Android7.0中文文档(API) -- HorizontalScrollView
- Android7.0中文文档(API)--- FrameLayout
- Android7.0中文文档(API)--- CalendarView
- Android7.0中文文档(API)--- DatePicker
- Android7.0中文文档(API) --- MediaController
- Android7.0中文文档(API)--- TabHost
- Android7.0中文文档(API) -- TimePicker
- Android7.0中文文档(API)-- ViewAnimator
- Android7.0中文文档(API)--- AbsoluteLayout
- Android7.0中文文档(API) -- Switch
- Android7.0中文文档(API) --- ToggleButton
- Android7.0中文文档(API) --- RadioButton
- Android7.0中文文档(API) --- CheckedTextView
- Android7.0中文文档(API) -- ScrollView
- Android7.0中文文档(API)-- DigitalClock
- Android7.0中文文档(API)-- TextClock
- Android7.0中文文档(API)---Chronometer
- c++ primer(二)
- jMetal使用教程(一)
- 在 C# 中实现 Singleton
- 传输介质-双绞线
- 流畅的python学习笔记
- Android7.0中文文档(API) --- Button
- 多种排序算法求中位数
- Python学习之旅-16
- Android6.0蓝牙开发中获取附近低功耗蓝牙设备结果权限问题分析
- 基于WebSocket的简易聊天室
- Android 简捷地为ListView添加上拉加载
- android基础学习12——内容提供者ContentProvider的使用
- Oracle number数据类型介绍
- Nodejs