android中常见控件

一、文本控件

1.TextView

显示文本,不允许编程,antoLink属性可设置突出显示的如URL,或者通过setAutoLinkMask函数

2.EditText

文本编程 intputType属性可输入的类型

3.AutoCompleteText

具有自动完成功能的EidtText。即用户图稿的时间显示建议输入供用户选择

XML声明

 <AutoCompleteTextView 
        android:id="@+id/actv"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />

java 代码

	AutoCompleteTextView actv =(AutoCompleteTextView)findViewById(R.id.actv);
		ArrayAdapter<String> aa=new ArrayAdapter<String>(this,
				android.R.layout.simple_dropdown_item_1line,
				new String[]{"English","Amercan","Chinese","German"});
		actv.setAdapter(aa);


4.MultiCompleteTextView

输入一个句子,每个单词的建议

与AutoCompleteTextView类似的配置,在最后用setTokenizer( )函数绑定需要触发提示的符号

二、按钮控件

1.Button

一般用于处理单击事件

调用 包含量OnClickListener监听器类的setOnClickListener( ) 函数注册单击事件。当单击时,调用监听器的onClick()方法

2.ImageButton

通过src属性设置其图片资源,或者setImageResource( )。并可以为其添加使用选择器。设置在获得焦点与否时显示不同

如: 在/res/drawable文件夹下 新建一个imagebuttonselector.xml文件

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item 
        android:state_pressed="true"
        android:drawable="@drawable/button_pressed"
        ></item>
    <item
        android:state_focused="true"
        android:drawable="@drawable/button_focused"
         ></item>
    <item 
        android:drawable="@drawable/icon"
        ></item>
</selector>

在布局文件中将控件src属性设置为选择器

3.ToggleButton

开头按钮,具有两种状态的on /off 

  <ToggleButton 
        android:id="@+id/tb"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Toggle Button"
        android:textOn="Stop" 
        android:textOff="Run"
        />
4.CheckBox

复选框,调用 isChecked( )可以获取它的是否选中的状态

5.RadioButton

单选按钮,允许在同一组内只有一个可选,首先要创建RadioGroup,然后向组件中填充单选按键,一般用onCheckedChangeListener监听器

   <RadioGroup 
        android:id="@+id/gp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >
        <RadioButton 
            android:id="@+id/rb_male"
            android:text="male"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />
        <RadioButton 
            android:id="@+id/rb_female"
            android:text="female"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />
    </RadioGroup>
三、ImageView控件

四、日期时间控件

1.DatePicker

选择日期

2.TimePicker
选择时间

3.AnalogClock

模拟时钟

4.DigitalClock

数字时钟

五、MapView 控件

用于显示地图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值