Android中的基础组件
16lz
2021-01-23
基础组件
1.TextView
1. text 文本 setText getText2. textColor 文本颜色 #FFFFFF setTextColor getTextColor3. 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用的自身的OnCheckedChangedListenerRadioButton用的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中 是一个可以多选的按钮
更多相关文章
- Android RadioButton【单选按钮】的点击事件的两种方法
- 安卓课程十七 Button图文混排的按钮
- Android 建立文件夹、生成文件并写入文本文件内容
- Android多组件下Gradle统一配置
- Android 设置对话框中的确定按钮的 enabled 属性
- android 实现一个滚动文本
- 【Android 性能优化】布局渲染优化 ( GPU 过度绘制优化总结 | CP
- Android 使用富文本显示web上的内容
- Android实训案例(六)——四大组件之一BroadcastReceiver的基本使用