Android7.0中文文档(API) --- Button

完整内容,请查看:http://www.zhdoc.net/android/reference/android/widget/Button.html

Button

public class Button
extends TextView

java.lang.Object
   ↳android.view.View
    ↳android.widget.TextView
     ↳android.widget.Button
已知的直接子类


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 a View 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 a state 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 the android:background attribute. For more information and an example, see State 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值