冕宁住房和建设局网站,永久个人网站,上海市企业服务云,网站建设基本费用# Android基本UI控件## *TextView 文本框*### TextView常用用法| 主要方法 | 功能描述 || :----------: | :--------------------: || getText | 获得TextView对象的文本 || setText | 设置TextView对象的文本 || setTextColor | 设置文本显示的颜色 |Javaprivate TextView tex…# Android基本UI控件## *TextView 文本框*### TextView常用用法| 主要方法 | 功能描述 || :----------: | :--------------------: || getText | 获得TextView对象的文本 || setText | 设置TextView对象的文本 || setTextColor | 设置文本显示的颜色 |Javaprivate TextView textView;textView (TextView) findViewById(R.id.textView);textView.setText(文本内容);textView.setTextColor(Color.rgb(255,255,255)); //颜色的RGB值textView.getText().toString();### TextView标签属性| 属性名称 | 描述 || :---------------: | :----------: || android:text | 设置显示文本 || android:textColor | 设置文本颜色 || android:textSize | 设置文本大小 |xmlandroid:idid/textViewandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text文本内容android:textColor#000android:textSize20sp/---## *EditText 编辑框*### EditText常用方法| 方法 | 功能描述 || :------: | :------------------------: || getText | 得到EditText对象的文本 || setText | 设置文本内容 || setHints | 设置文本框为空时显示的文本 || getHints | 获取文本框为空时显示的文本 |javaprivate EditText editText;editText (EditText) findViewById(R.id.editText);String text editText.getText().toString();editText.setText(文本内容);editText.setHint(设置文本框为空时显示的文本);editText.getText();### EditText标签属性| 属性名称 | 描述 || :---------------: | :------------------------: || android:textColor | 设置文本颜色 || android:textSize | 设置文本大小 || android:hint | 设置文本框为空时显示的文本 || android:inputType | 限定文本框输入类型 |xmlandroid:idid/editTextandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:textColor#000android:hint设置文本框为空时显示的文本android:inputTypenumber/---## *ImageView 图片视图*### ImageView常用方法| 方法 | 功能描述 || :--------------: | :-------------------------------------------: || getDrawable | 返回视图的可绘制对象 || setImageBitmap | 设置位图为该ImageView内容 || setImageResource | 通过资源ID设置可绘制对象为ImageView显示的内容 || setAlpha | 设置透明度 |Javaprivate ImageView imageView;private Bitmap bitmap;imageView (ImageView) findViewById(R.id.imageView);imageView.setAlpha(80); //设置透明度为80%Drawable drawable imageView.getDrawable(); //得到drawable对象imageView.setImageResource(R.drawable.ic_launcher_background);imageView.setImageBitmap(bitmap);### ImageView标签属性| 属性名称 | 描述 || :---------: | :-------------------------------: || android:src | 设置可绘制对象为ImageView显示内容 |xmlandroid:idid/imageViewandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:srcdrawable/ic_launcher_background/---## *Button 按钮*### Button常用方法略### Button标签属性| 属性 | 描述 || :---------------: | :----------------------: || android:text | 设置按钮文本内容 || android:hint | 设置按钮为空时显示的文本 || android:textColor | 设置按钮文本颜色 || android:textSize | 设置按钮文本大小 || android:enabled | 设置按钮是否打开 |xmlandroid:idid/buttonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text按钮文本android:textColor#000android:hint按钮为空时显示的文本android:textSize20spandroid:enabledtrue/---## *CheckBox 复选框*### CheckBox 常用方法| 方法 | 功能描述 || :--------: | :--------------: || isChecked | 判断组件是否勾选 || setChecked | 设置组件状态 |javaprivate CheckBox checkBox;checkBox (CheckBox) findViewById(R.id.checkBox);Boolean isChecked checkBox.isChecked(); //判断CheckBox是否选中checkBox.setChecked(true); //设置CheckBox为选中状态### CheckBox标签属性| 属性 | 描述 || :-------------: | :--------------: || android:checked | 设置CheckBox状态 |xmlandroid:idid/checkBoxandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:checkedtrue/---## *RadioGroup和RadioButton 单项选择按钮*### RadioGroup常用方法| 方法 | 功能描述 || :--------: | :------------------: || checked | 单选按钮组的勾选状态 || chearCheck | 清除当前选择状态 |javaprivate RadioButton rb1;private RadioButton rb2;private RadioButton rb3;private RadioGroup radioGroup;rb1 (RadioButton) findViewById(R.id.rb1);rb2 (RadioButton) findViewById(R.id.rb2);rb3 (RadioButton) findViewById(R.id.rb3);radioGroup (RadioGroup) findViewById(R.id.radioGroup);radioGroup.check(R.id.rb1); //选中id为rb1的单选框radioGroup.clearCheck(); //清除当前选中状态### RadioGroup标签属性略xmlandroid:idid/radioGroupandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:idid/rb1android:layout_widthwrap_contentandroid:layout_heightwrap_content /android:idid/rb2android:layout_widthwrap_contentandroid:layout_heightwrap_content /android:idid/rb3android:layout_widthwrap_contentandroid:layout_heightwrap_content /---## *ToggleButton 开关按钮*### ToggleButton常用方法| 方法 | 功能描述 || :--------: | :------------------: || getTextoff | 获取失效状态下的文本 || getTextOn | 获取有效状态下的文本 || setChecked | 设置开关状态 || setTextOff | 设置失效状态下的文本 || setTextOn | 设置有效状态下的文本 |javaprivate ToggleButton toggleButton;toggleButton (ToggleButton) findViewById(R.id.toggleButton);String textOff toggleButton.getTextOff().toString(); //获取失效状态下的文本String textOn toggleButton.getTextOn().toString();toggleButton.setTextOff(失效状态下的文本);toggleButton.setTextOn(有效状态下的文本);toggleButton.setChecked(true); //设置开关为打开状态### ToggleButton标签属性| 属性名称 | 描述 || :-------------: | :--------------: || android:textOff | 未选中时按钮文本 || android:textOn | 选中时按钮文本 || android:checked | 设置按钮状态 |xmlandroid:idid/toggleButtonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:textOn选中时按钮文本android:textOff未选中时按钮文本android:checkedfalse/---## *SeekBar 拖动条*### SeekBar 常用方法| 方法 | 功能描述 || :---------: | :------------: || getMax | 获取范围最大值 || getProgress | 获取当前进度值 || setMax | 设置范围最大值 |Javaprivate SeekBar seekBar;seekBar (SeekBar) findViewById(R.id.seekBar);seekBar.setMax(100); //设置拖动条最大值为100seekBar.getMax(); //得到当前拖动条的最大值seekBar.getProgress(); //获取当前进度值### SeekBar标签属性| 属性名称 | 描述 || :--------------: | :------------: || android:max | 设置范围最大值 || android:progress | 设置当前进度值 |xmlandroid:idid/seekBarandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:max250android:progress100/---## *ProgressBar 进度条*### ProgressBar 常用方法| 方法 | 功能描述 || :---------: | :------------: || getMax | 获取范围最大值 || getProgress | 获取当前进度值 |javaprivate ProgressBar progressBar;progressBar (ProgressBar) findViewById(R.id.progressBar);progressBar.getMax();progressBar.getProgress(); //获取当前进度### ProgressBar 标签属性| 属性名称 | 描述 || :--------------: | :--------------------: || android:max | 设置进度条最大值 || android:progress | 设置进度条的默认进度 || style | 进度条样式(详情见下表) || 进度条样式 | 描述 || :----------------------------------------------: | :--------------: || style?android:attr/progressBarStyleHorizontal | 水平长形进度条 || style?android:attr/progressBarStyleLarge | 超大号圆形进度条 || style?android:attr/progressBarStyleSmall | 标准圆形进度条 || style?android:attr/progressBarStyleSmallTitle | 标题型圆形进度条 |xmlandroid:idid/progressBarandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:max250android:progress100style?android:attr/progressBarStyleHorizontal/---一键复制编辑Web IDE原始数据按行查看历史