读书人

以 android\packages\app\voiceDialer

发布时间: 2013-01-07 10:02:25 作者: rapoo

以 android\packages\app\voiceDialer 为例, 如何在界面上加一个按钮
以 android\packages\app\voiceDialer 为例, 如何在界面上加一个按钮呢?

1) 先 res\layout\x.xml 中加一个 button 标识.

这个 button 标识在界面上的位置如何定位呢?

2) 如何按钮点击事件处理?
[解决办法]
[quote=引用:]
.....[quote]
拿2L的代码为例子.... 先在activity_main.xml中定义一个Button控件 如下:
?<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>

<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/about_button" />
</LinearLayout>

再在相应的Activity类中 通过setContentView(R.layout.activity_main);加载activity_main.xml布局

通过Button b = (Button)findViewById(R.id.about_button); 获得Button对象

2L setOnClickListener方法 注册按钮点击事件 希望LZ还是看看android基础视频什么的

读书人网 >Android

热点推荐