android 基本控件.ppt_第1页
android 基本控件.ppt_第2页
android 基本控件.ppt_第3页
android 基本控件.ppt_第4页
android 基本控件.ppt_第5页
已阅读5页,还剩31页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、1,android 基本控件,疯狂android里面讲的超级详细,2,基本控件关系图,3,TextView、EditView、AutoCompleteTextView,Button、ImageButton、,RadioButton、CheckBox、ToggleButton,ProgressBar进度条,SekBar拖动条,RatinBar星级评分条,4,TextView、EditView、AutoCompleteTextView,Base Use,TextView显示文本内容,EditView输入文本内容, 基本的设置文字大小,颜色,各个字体之间的宽度,限制输入长度或行数,类型、过长的文本省

2、略在何处等最基本操作,可编辑与不可编辑,mEditText.setFocusable(true); mEditText.setFocusable(false); 显示与否 android:visibility=visible、invisible、gone mlistview1.setVisibility(View.GONE); TextView官方文档解说 http:/www.open- Android textview字体颜色显示和图片显示,5,TextView,设置超链android:autoLink=web|email 显示文本会自动加横线为超链,例如显示文字 欢迎大家访问我的博客: -

3、 android:ellipsize=”start”省略号显示在开头 2.android:ellipsize=”end”省略号显示在结尾 3.android:ellipsize=”middle”-省略号显示在中间 - 4.android:ellipsize=”marquee”以跑马灯的方式显示(动画横向移动) 文字左右滚动三个属性: android:singleLine=true android:ellipsize=marquee (tv.setMovementMethod(ScrollingMovementMethod.getInstance();) android:marqueeRepea

4、tLimit=marquee_forever 在ellipsize指定marquee的情况下,设置重复滚动的次数,当设置为marquee_forever时表示无限次 android:maxLines=15 ,6,EditText,welcome to use these PowerPoint templates, New Content design, 10 years experience,限制为输入, android:inputType= 设置只能输入数字,字母,密码,电话,日期,小数等等,也有提示文本输入。 非限制情况下可用代码设置,html颜色,字体,下划线,甚至是插入图片。 edit

5、Text2.setText(Html.fromHtml( 红色代码 + 蓝色斜体代码+蓝色斜体加粗体下划线代码); void SetImage(int dra) Drawable drawable=getResources().getDrawable(dra); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(); SpannableString spannableString = new SpannableString(pics); ImageSpan imageSpan=n

6、ew ImageSpan(drawable,ImageSpan.ALIGN_BASELINE); spannableString.setSpan(imageSpan, 0, spannableString.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); editText3.setText(spannableString); ,7,EditText,welcome to use these PowerPoint templates, New Content design, 10 years experience,限制为输入, android:input

7、Type= 设置只能输入数字,字母,密码,电话,日期,小数等等,也有提示文本输入。 非限制情况下可用代码设置,html颜色,字体,下划线,甚至是插入图片。 editText2.setText(Html.fromHtml( 红色代码 + 蓝色斜体代码+蓝色斜体加粗体下划线代码); void SetImage(int dra) Drawable drawable=getResources().getDrawable(dra); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight();

8、SpannableString spannableString = new SpannableString(pics); ImageSpan imageSpan=new ImageSpan(drawable,ImageSpan.ALIGN_BASELINE); spannableString.setSpan(imageSpan, 0, spannableString.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); editText3.setText(spannableString); ,8,EditText, /文本类型,多为大写、小写和数字符号。

9、android:inputType=none/输入普通字符 android:inputType=text/输入普通字符 android:inputType=textCapCharacters/输入普通字符 android:inputType=textCapWords/单词首字母大小 android:inputType=textCapSentences/仅第一个字母大小 android:inputType=textAutoCorrect/前两个自动完成 android:inputType=textAutoComplete/前两个自动完成 android:inputType=textMultiLi

10、ne/多行输入 android:inputType=textImeMultiLine/输入法多行(不一定支持) android:inputType=textNoSuggestions/不提示 android:inputType=textUri/URI格式 android:inputType=textEmailAddress/电子邮件地址格式 android:inputType=textEmailSubject/邮件主题格式,android:inputType=textShortMessage/短消息格式 android:inputType=textLongMessage/长消息格式 andro

11、id:inputType=textPersonName/人名格式 android:inputType=textPostalAddress/邮政格式 android:inputType=textPassword/密码格式 android:inputType=textVisiblePassword/密码可见格式 android:inputType=textWebEditText/作为网页表单的文本格式 android:inputType=textFilter/文本筛选格式 android:inputType=textPhonetic/拼音输入格式 /数值类型 android:inputType=n

12、umber/数字格式 android:inputType=numberSigned/有符号数字格式 android:inputType=numberDecimal/可以带小数点的浮点格式 android:inputType=phone/拨号键盘 android:inputType=datetime/日期+时间格式 android:inputType=date/日期键盘 android:inputType=time/时间键盘,9,EditView,welcome to use these PowerPoint templates, New Content design, 10 years exp

13、erience,设置光标起始位置,颜色;横屏时软键盘的设定,大小写自动转换等等。 ,10,AutoCompleteTextView,welcome to use these PowerPoint templates, New Content design, 10 years experience,不是Android的常用控件,但是它的实用性还是很强的 completionThreshold:它的值决定了你在AutoCompleteTextView至少输入几个字符,它才会具有自动提示的功能。另,默认最多提示20条。 dropDownAnchor:它的值是一个View的ID,指定后,AutoCom

14、pleteTextView会在这个View下弹出自动提示。 dropDownSelector:应该是设置自动提示的背景色之类。dropDownWidth:设置自动提示列表的宽度。 ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, COUNTRIES); autocompletetextView.setAdapter(adapter); ,11,Button、ImageButton,Base Use,基本的设置文字大小,颜色,背景,各个字体之间的宽度,形状,可单击与

15、不可单击,button.setClickable(false)长按,单击,变色与否等等,样式设计,圆角。颜色。监听。 显示与否 android:visibility=visible、invisible、gone button.setVisibility(View.GONE); background=null 图片的框框不在,12,Button 属性,selector背景选择器,android的selector是在drawable/xxx.xml中配置 android:drawable 放一个drawable资源 android:state_pressed 是否按下,如一个按钮触摸或者点击。 a

16、ndroid:state_focused 是否取得焦点,比如用户选择了一个文本框。 android:state_hovered 光标是否悬停,通常与focused state相同,它是4.0的新特性 android:state_selected 被选中,它与focus state并不完全一样,如一个list view 被选中的时候,它里面的各个子组件可能通过方向键,被选中了。 android:state_checkable 组件是否能被check。如:RadioButton是可以被check的。 android:state_checked 被checked了,如:一个RadioButton可以

17、被check了。 android:state_enabled 能够接受触摸或者点击事件 android:state_activated 被激活 android:state_window_focused 应用程序是否在前台,当有通知栏被拉下来或者一个对话框弹出的时候应用程序就不在前台了,13,Button 属性, /shape可以单独在drawable设置成xml,也是xml ,14,Button单击换样式,welcome to use these PowerPoint templates, New Content design, 10 years experience,11,15,ImageB

18、utton,android:src=drawable/xxx 设置单击前后的照片切换,16,src /绑定一个匿名监听器 group.setOnCheckedChangeListener(new OnCheckedChangeListener() Override public void onCheckedChanged(RadioGroup arg0, int arg1) / TODO Auto-generated method stub /获取变更后的选中项的ID int radioButtonId = arg0.getCheckedRadioButtonId(); /根据ID获取Radi

19、oButton的实例 RadioButton rb = (RadioButton)MyActiviy.this.findViewById(radioButtonId); dosomething. /更新文本内容,以符合选中项 tv.setText(您的性别是: + rb.getText(); );,22,CheckBox,c1 = (CheckBox) findViewById(R.id.CheckBox01); c2 = (CheckBox) findViewById(R.id.CheckBox02); c1.setOnCheckedChangeListener(new CheckBoxLi

20、stener(); c2.setOnCheckedChangeListener(new CheckBoxListener(); class CheckBoxListener implements OnCheckedChangeListener Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) if(isChecked) Toast.makeText(CheckBoxActivity.this, buttonView.getText()+被选择,Toast.LENGTH_SHOR

21、T ).show(); else Toast.makeText(CheckBoxActivity.this, buttonView.getText()+取消选择,Toast.LENGTH_SHORT ).show(); , ,23,CheckBox,排版 可以定义多个checkBox,24,自定义,/res/xml/my_preference.xml /res/layout/my_checkbox.xml ./res/drawable/checkbox_checked_style.xml 其实不用在my_preference.xml中设置, 直接在引用checkbox的布局中,设置checkb

22、ox的button属性为drawable/checkbox_checked_style,.MainActivity.java注意要继承PreferenceActivity public class MainActivity extends PreferenceActivity Override public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.my_preference); ,25,ToggleButton/Sw

23、itch,与之前非常相似,主要功能区别, ToggleButton/Switch主要用于某种功能的切换 特有的xml属性 android:textOff/setTextOff(CharSequence):设置关闭时显示内容。android:textOn/setTextOn(CharSequence):设置打开时显示内容。 OnCheckedChangeListener() 针对Switch android:textStylesetSwitchTpyeface(Typeface) 设置开关的风格 android:thumbsetTumbResourse(int) 设置开关按钮 android:t

24、racksetTrackResource(int) 设置开关轨道 ,26,ToggleButton/Switch,27,ProgressBar进度条,SekBar拖动条,RatinBar星级评分条,Base Use,28,ProgressBar进度条,welcome to use these PowerPoint templates, New Content design, 10 years experience,xml里面的代码 设置大小主要是 style=?android:attr/progressBarStyleLarge style=?android:attr/progressBarS

25、tyleSmall 设置标题栏的进度条,就要在setCView前后加 requestWindowFeature(Window.FEATURE_PROGRESS); /设置窗口进度条特性风格 setProgressBarIndeterminateVisibility(true); /设置进度条可见性: 长方形 style=?android:attr/progressBarStyleHorizontal android:max=100 最大进度值100 android:progress=25 当前初始化进度值25 android:secondaryProgress=50 当前初始化第2进度值50,

26、29,自定义进度条旋转动画,style=android:style/layer-list fromDegrees 为动画起始时物件的角度 toDegrees 属性为动画结束时物件旋转的角度 可以大于360度 当角度为负数表示逆时针旋转 当角度为正数表示顺时针旋转 (负数fromto正数:顺时针旋转) (负数fromto负数:逆时针旋转) (正数fromto正数:顺时针旋转) (正数fromto负数:逆时针旋转) pivotX、pivotY;为动画相对于物件的X、Y坐标的开始位 以上两个属性值 从0%-100%中取值 50%为物件的X或Y方向坐标上的中点位置 android:indetermin

27、ateOnly 如果设置为true那么忽略进度显示呈现循环动画 android:indeterminateDrawable显示自定义旋转XML,30,自定义进度条样式,android:progressDrawable=drawable/progressbar /自定义进度条 drawable目录下新增progressbar.xml文件,可以设置默认背景色和进度条的颜色 (值得一提的是支持渐变色) gradient android:startColor=#80ffd300 android:centerColor=#80ffb600 android:centerY=0.75 android:end

28、Color=#a0ffcb00 android:angle=0,/ ,31,SeekBar拖动条,welcome to use these PowerPoint templates, New Content design, 10 years experience,xml里面的代码 设置大小主要是 android:minHeight=5dip android:maxHeight=5dip 设置拖动条的样式跟滑块样式 android:progressDrawable=drawable/seek_img android:thumb=drawable/thumb /设置监听,要在外面设定初始值 sou

29、ndBar.setMax(maxVolume);soundBar.setProgress(currentVolume); soundBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() /调音监听器 public void onProgressChanged(SeekBar arg0,int progress,boolean fromUser) audiomanage.setStreamVolume(AudioManager.STREAM_MUSIC, progress, 0); currentVolume = audioma

30、nage.getStreamVolume(AudioManager.STREAM_MUSIC); /获取当前值 soundBar.setProgress(currentVolume); ,Override public void onStartTrackingTouch(SeekBar seekBar) / TODO Auto-generated method stub Override public void onStopTrackingTouch(SeekBar seekBar) / TODO Auto-generated method stub ,32,自定义拖动条样式,android:

31、progressDrawable=drawable/seek_img android:thumb=drawable/thumb seek_img.xml ,thumb.xml ,33,RatinBar星级评分条,welcome to use these PowerPoint templates, New Content design, 10 years experience,xml里面的代码 基于SeekBar和ProgressBar的扩展,用星型来显示等级评定。 使用RatingBar的默认大小时,用户可以触摸/拖动或使用键来设置评分, 小风格ratingBarStyleSmall,大风格ratingBarStyleIndicator), android:stepSize(评分步

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论