首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

以 android\packages\app\voiceDialer 为例, 怎么在界面下加一个按钮

2013-01-07 
以 android\packages\app\voiceDialer为例, 如何在界面上加一个按钮以 android\packages\app\voiceDialer

以 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基础视频什么的

热点排行