Android中的基础组件

基础组件

1.TextView

1. text 文本 setText getText
2. textColor 文本颜色 #FFFFFF setTextColor getTextColor
3. textSize 文本大小 sp setTextColor(Color.Blue) getTextColor();
4. textSytle 文本样式 没有java代码 (设置画笔)
5. gravity 文本对齐方式 center 

2.Button

根TextView一样

3.ImageView

1.src 前置图片 setImageResource(R.drawable.xxx);
2. scaleType setScaleType(ScaleType.XXX); 

4.EditText

1.ems:汉字显示宽度
2. maxLenght : 最大字符
3. hint: 提示
4. textColorHint:提示的颜色
5. inputType: 设置密码,设置数字(切换到数字键盘);
6. digits : 只允许用户输入的字符
7. singleLine : 单行模式
8. imeOptions: 设置软键盘回车键的样式
9.
10. EditText独有的事件
11. addTextChangeListener();
12. 主要的方法
13.
14. onTextChanged(CharSequence 当前的字符串, int start, int before, int count) 

5.RadioButton 单选按钮

RadioButton必须放在一个RadioGroup中
xml中禁止使用checked属性
一般来说 使用RadioGroup的监听方法
监听注意导包,RadioGroup用的自身的OnCheckedChangedListener
RadioButton用的CompoundsButton的OnCheckedChangeListener 
RadioButton可以设置该button字体上.下.左.右的图片
RadioGroup中,如果给定了id号,那么使用R.id,如果没有,使用改元素的索引,从1开始

一个案例如下图

这里写图片描述

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal" >

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:button="@null"
            android:drawableTop="@drawable/message_selected"
            android:gravity="center"
            android:text="回话" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:button="@null"
            android:drawableTop="@drawable/contacts_unselected"
            android:gravity="center"
            android:text="联系人" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:button="@null"
            android:drawableTop="@drawable/news_unselected"
            android:gravity="center"
            android:text="动态 " />
    </RadioGroup>

</RelativeLayout>

6.CheckBox多选按钮

同RadioButton 不需要放在一个RadioGroup中  是一个可以多选的按钮
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值