如何在Android中添加一个按钮? [英] How to add a button in android?
本文介绍了如何在Android中添加一个按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能告诉如何在Android中添加一个按钮?
Can anybody tell how to add a button in android?
推荐答案
勾选此的Android按键教程;这个简单的例子创建了一个关闭按钮。
Check this Android Button tutorial; this simple example creates a Close Button.
所有你需要做的是:
1.新增按钮组件到您的布局
1.Add Button widget to your Layout
<Button android:id="@+id/close"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="@string/title_close" />
2.Attach一个setOnClickListener方法按钮实例:
2.Attach a setOnClickListener method to the button instance:
protected void onCreate(Bundle savedInstanceState) {
this.setContentView(R.layout.layoutxml);
this.closeButton = (Button)this.findViewById(R.id.close);
this.closeButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
这篇关于如何在Android中添加一个按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文