常用控件

. TextView 文本框

主要方法 TextView ,getDefaultMovementmethod ,getText ,length, getEditableText ,


TextView 是用于显示字符串的组件,对于用户来说就是屏幕中一块用于显 示文本的区域。    

FrameLayout是一个布局,名叫桢布局。

FrameLayout 是布局中最简单的一个布局,在这个布局中,整个界面被当成一 块空白备用区域, 所有的子元素都不能被指定放置的位置,它们统统放于这块区 域的左上角, 并且后面的子元素直接覆盖在前面的子元素之上,将前面的子元素 部分和全部遮挡。

[html]  view plain  copy
  1. <FrameLayout  
  2.            android:layout_width="match_parent"  
  3.            android:layout_height="match_parent"  
  4.            android:id="@+id/linear1"  
  5.            >  
  6.            <EditText  
  7.                android:layout_width="match_parent"  
  8.                android:layout_height="wrap_content"  
  9.                android:inputType="numberSigned"  
  10.                android:background="@drawable/et_selector"  
  11.                android:paddingLeft="150dp"  
  12.                android:hint="请输入用户名"  
  13.                android:textSize="30dp"  
  14.                />  
  15.            <TextView  
  16.                android:layout_width="wrap_content"  
  17.                android:layout_height="wrap_content"  
  18.                android:drawableLeft="@drawable/icon_user"  
  19.                android:text="用户名:"  
  20.                android:textSize="30dp"  
  21.                />  
  22.        </FrameLayout>  

2 .EditText 编辑框
EditText 和 TextView 的功能基本类似,他们之间的主要区别在于 EditText 提 供了可编辑的文本框。


请输入用户名是用户填写的数据,上面的代码就是EditText的用法:

3. Button 按钮


Button是点击事件和按钮是一个意思,当你点击他时你能根据他调用一个方法比如说:

[html]  view plain  copy
  1. <EditText  
  2.         android:layout_width="match_parent"  
  3.         android:layout_height="wrap_content"  
  4.         android:hint="请输入用户名"  
  5.         android:id="@+id/btn_main_uers"  
  6.         />  
  7.     <EditText  
  8.         android:layout_width="match_parent"  
  9.         android:layout_height="wrap_content"  
  10.         android:hint="密码"  
  11.         android:id="@+id/btn_main_pass"  
  12.         />  
  13.   <Button  
  14.       android:layout_width="match_parent"  
  15.       android:layout_height="wrap_content"  
  16.       android:text="确认"  
  17.       android:id="@+id/btn_main_ok"  
  18.       android:onClick="login"  
  19.       />  
根据所写的id 给按钮设置点击的监听:

Button 
test_main= (Button) findViewById(R.id.btn_main_ok);
	//方法
	test_main.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(View v) {
           Toast  t=Toast.makeText(MainActivity.this,"你好呀",Toast.LENGTH_LONG);
           t.setGravity(Gravity.TOP,0,0);
t.show();

      4 CheckBox 多项选择

        多项选择 CheckBox 组件也被称为复选框, 该组件常用于某选项的打开或者关闭。

[html]  view plain  copy
  1. <TextView  
  2.           android:layout_width="wrap_content"  
  3.           android:layout_height="wrap_content"  
  4.           android:text="爱好:"  
  5.           />  
  6.         <CheckBox  
  7.             android:layout_width="wrap_content"  
  8.             android:layout_height="wrap_content"  
  9.             android:text="吃饭"  
  10.             android:id="@+id/btn_main_chi"  
  11.             />  
  12.   
  13.   <CheckBox  
  14.       android:id="@+id/btn_main_sellp"  
  15.       android:layout_width="wrap_content"  
  16.       android:layout_height="wrap_content"  
  17.       android:text="睡觉" />  
  18.   
  19.   <CheckBox  
  20.       android:id="@+id/btn_main_cat"  
  21.       android:layout_width="wrap_content"  
  22.       android:layout_height="wrap_content"  
  23.       android:text="打豆豆" />  
  24.   
  25.   <Button  
  26.       android:layout_width="wrap_content"  
  27.       android:layout_height="wrap_content"  
  28.       android:text="确认"  
  29.       android:id="@+id/btn_main_aiok"  
  30.       />  

5 .RadioGroup、RadioButton 单项选择
RadioButton 指的是一个单选按钮,它有选中和不选中两种状态,而 RadioGroup 组件也被称为单项按钮组,它可以有多个 RadioButton。

[html]  view plain  copy
  1. <TextView  
  2.         android:layout_width="match_parent"  
  3.         android:layout_height="wrap_content"  
  4.         android:text="性别:"  
  5.         />  
  6.   
  7.     <RadioGroup  
  8.         android:layout_width="match_parent"  
  9.         android:layout_height="wrap_content"  
  10.         android:id="@+id/rg_main_sex"  
  11.         >  
  12.         <RadioButton  
  13.             android:layout_width="wrap_content"  
  14.             android:layout_height="wrap_content"  
  15.             android:text="男"  
  16.             android:id="@+id/rb_main_boy"  
  17.             android:checked="true"  
  18.             />  
  19.         <RadioButton  
  20.             android:layout_width="wrap_content"  
  21.             android:layout_height="wrap_content"  
  22.             android:text="女"  
  23.             android:id="@+id/rb_main_girl"  
  24.             />  
  25.     </RadioGroup>  

6. Toast 提示
Toast 是 Android 提供的“快显讯息”类,它的用途很多,使用起来非常的 简单,主要用于显示信息。

Toast.makeText(MainActivity.this,"你好呀",Toast.LENGTH_LONG).show();//可以直接吐司在界面上。

  7. DatePicker 日期

DatePicker 日期选择器是一个选择年月日的日历布局视图

[html]  view plain  copy
  1. public void data(View view){  
  2.        Calendar calendar=Calendar.getInstance();  
  3.        int  yearcalendar.get(Calendar.YEAR);//获取年  
  4.        int month=calendar.get(Calendar.MONTH);//获取月  
  5.        int daycalendar.get(Calendar.DAY_OF_MONTH);//获取这个月的当前日  
  6.        DatePickerDialog dpd=new DatePickerDialog(this,new DatePickerDialog.OnDateSetListener(){  
  7.            @Override  
  8.            public void onDateSet(DatePicker view, int year, int month, int day) {  
  9.                Log.i("date",year+"年"+month+"月"+day+"日");  
  10.            }  
  11.        },year,month,day);  
  12.        dpd.show();  
  13.    }  
8.  TimePicker 时间选择器

TimePicker 时间选择器是用于选择一天中时间的视图
1.public Integer getCurrentMinute () 获取当前时间的分钟部分。 返回值 当前分钟。 

2.public boolean is24HourView () 获取当前系统设置是否是 24 小时制。 

3.public void setCurrentHour (Integer currentHour) 设置当前小时。

4.public void setCurrentMinute (Integer currentMinute) 设置当前分钟(0-59)。

5.public void setEnabled (boolean enabled) 设置可用的视图状态。

[html]  view plain  copy
  1. public void getTime(View view){  
  2.     //获取当前系统时间  
  3.     Calendar c=Calendar.getInstance();  
  4.     int hour=c.get(Calendar.HOUR_OF_DAY);  
  5.     int minute=c.get(Calendar.MINUTE);  
  6.   
  7.     //弹出时间对话框  
  8.     TimePickerDialog tpd=new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {  
  9.         @Override  
  10.         public void onTimeSet(TimePicker timePicker, int i, int i1) {  
  11.             Log.i("test","时间:"+i+":"+i1);  
  12.         }  
  13.     },hour,minute,true);  
  14.     //细节:弹  
  15.     tpd.show();  
  16. }  
 9.ImageView 图片视图
ImageView 显示任意图像, 例如图标。 ImageView 类可以加载各种来源的图片 (如 资源或图片库),需要计算图像的尺寸,比便它可以在其他布局中使用,并提供 例如缩放和着色(渲染)各种显示选项。



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值