欢迎来到天天文库
浏览记录
ID:6163876
大小:2.57 MB
页数:41页
时间:2017-11-14
《android常用控件及使用方法》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、UnicairCommunicationTecCo.,Ltd.烟台友开通信技术有限公司1.TextView的用法2.EditText的用法3.Button的用法4.ImageButton的用法5.CheckBox的用法6.RadioButton的用法7.Spinner的用法8.LiseView的用法9.TabHost的用法10.ScrollView的用法11.ProgressBar的应用12.ImageView的应用13.AutoCompleteTextView的应用14.ImageSwitcher&Gallery的应用1
2、5.GridView的应用TextView是一种用于显示字符串的控件EditText则是用来输入和编辑字符串的控件EditText是一个具有编辑功能的TextView建立一个“TextViewDemo”的程序,包含TextView和EditText两个控件。上方“用户名”部分使用的是TextView,下方的文字输入框使用的是EditText。TextView&EditTextTextViewDemo在XML文件中的代码3、idth="wrap_content"android:layout_height="wrap_content"android:text="TextView01">第2行的android:layout_width属性用来4、设置TextView的宽度,wrap_content表示TextView宽度只要能够包含所显示的字符串即可第3行的android:layout_height属性用来设置TextView的高度第4行表示TextView所显示的字符串,在后面将通过代码更改TextView的显示内容第7行中“fill_content”表示EditText的宽度将等于父控件的宽度TextViewDemo.java文件中代码的修改TextViewtextView=(TextView)findViewById(R.id.TextView01);Edi5、tTexteditText=(EditText)findViewById(R.id.EditText01);textView.setText("用户名:");editText.setText("");第1行代码的findViewById()函数能够通过ID引用界面上的任何控件,只要该控件在XML文件中定义过ID即可。第3行代码的setText()函数用来设置TextView所显示的内容。Button是一种按钮控件,用户能够在该控件上点击,并能引发相应的事件处理函数。ImageButton用以实现能够显示图像功能的控件按钮。6、建立一个“ButtonDemo”的程序,包含Button和ImageButton两个按钮,上方是“Button按钮”,下方是一个ImageButton控件。ButtonDemo在XML文件中的代码7、ImageButton01"android:layout_width="wrap_content"android:layout_height="wrap_content">定义Button控件的高度、宽度和内容定义ImageButton控件的高度和宽度,但是没定义显示的图像,在后面的代码中进行定义Button&ImageButton@引入资源1.将download.png文件拷贝到/res/drawable文件夹下2.在/res目录上选择Refresh,新添加的文件将显示/res/drawabl8、文件夹下*R.java文件内容也得到了更新*否则提示无法找到资源的错误更改Button和ImageButton内容,引入android.widget.Button和android.widget.ImageButtonButtonbutton=(Button)findViewById(R.id.Butto
3、idth="wrap_content"android:layout_height="wrap_content"android:text="TextView01">第2行的android:layout_width属性用来
4、设置TextView的宽度,wrap_content表示TextView宽度只要能够包含所显示的字符串即可第3行的android:layout_height属性用来设置TextView的高度第4行表示TextView所显示的字符串,在后面将通过代码更改TextView的显示内容第7行中“fill_content”表示EditText的宽度将等于父控件的宽度TextViewDemo.java文件中代码的修改TextViewtextView=(TextView)findViewById(R.id.TextView01);Edi
5、tTexteditText=(EditText)findViewById(R.id.EditText01);textView.setText("用户名:");editText.setText("");第1行代码的findViewById()函数能够通过ID引用界面上的任何控件,只要该控件在XML文件中定义过ID即可。第3行代码的setText()函数用来设置TextView所显示的内容。Button是一种按钮控件,用户能够在该控件上点击,并能引发相应的事件处理函数。ImageButton用以实现能够显示图像功能的控件按钮。
6、建立一个“ButtonDemo”的程序,包含Button和ImageButton两个按钮,上方是“Button按钮”,下方是一个ImageButton控件。ButtonDemo在XML文件中的代码7、ImageButton01"android:layout_width="wrap_content"android:layout_height="wrap_content">定义Button控件的高度、宽度和内容定义ImageButton控件的高度和宽度,但是没定义显示的图像,在后面的代码中进行定义Button&ImageButton@引入资源1.将download.png文件拷贝到/res/drawable文件夹下2.在/res目录上选择Refresh,新添加的文件将显示/res/drawabl8、文件夹下*R.java文件内容也得到了更新*否则提示无法找到资源的错误更改Button和ImageButton内容,引入android.widget.Button和android.widget.ImageButtonButtonbutton=(Button)findViewById(R.id.Butto
7、ImageButton01"android:layout_width="wrap_content"android:layout_height="wrap_content">定义Button控件的高度、宽度和内容定义ImageButton控件的高度和宽度,但是没定义显示的图像,在后面的代码中进行定义Button&ImageButton@引入资源1.将download.png文件拷贝到/res/drawable文件夹下2.在/res目录上选择Refresh,新添加的文件将显示/res/drawabl
8、文件夹下*R.java文件内容也得到了更新*否则提示无法找到资源的错误更改Button和ImageButton内容,引入android.widget.Button和android.widget.ImageButtonButtonbutton=(Button)findViewById(R.id.Butto
此文档下载收益归作者所有