androidstudio常用标签——文本框(案例—用户注册)
2023年7月13日发(作者:)
androidstudio常⽤标签——⽂本框(案例—⽤户注册)⽂本框常⽤属性1、text:⽂本框的⽂本内容2、maxLines:最⼤⾏数3、lines:⾏数4、inputType:输⼊数据类型5、hint:提⽰6、textColor:⽂本颜⾊7、textSize:⽂本字号8、textColorHint:提⽰⽂本颜⾊9、singleLine:⽂本是否单⾏(true, false)涉及知识点1、线性布局(LinearLayout)2、标签(TextView)3、编辑框(EditText)4、按钮(Button)5、意图(Intent)6、数据包(Bundle)实现步骤1.准备两张背景图⽚,⼀个⽤于注册界⾯背景(registrationbg),⼀个⽤于输出信息界⾯背景(informationbg),将图⽚拷贝到mipmap中2.将默认xml的名字改为activity_registration,将默认java⽂件的名字改为RegistrationActivity。3.新建⼀个Java⽂件,看图这样基于模板创建会⾃动注册窗⼝,⽐较⽅便!4.我们现在可以在activity_registration编写代码了 5.我们现在可以写information_registration的代码了 这个时候information_activity中是没有任何数据的,因为我们要从的⽂件传送过去。6.编写代码 UserRegistration 设置 姓名: 性别: 年龄: 电话: 邮箱: 主页: 备注: 注册 取消7.我们现在写很关键的ckage gistration; import ty; import ; import ; import ; import xt;public class RegistrationActivity extends Activity { private EditText edtName; private EditText edtGender; private EditText edtAge; private EditText edtPhone; private EditText edtEmail; private EditText edtHomePage; private EditText edtMemo; @Override protected void onCreate(Bundle savedInstanceState) { te(savedInstanceState); // 利⽤布局⽂件设置⽤户界⾯ setContentView(ty_registration); // 通过资源标识获得控件⽰例 edtName = (EditText) findViewById(_name); edtGender = (EditText) findViewById(_gender); edtAge = (EditText) findViewById(_age); edtPhone = (EditText) findViewById(_phone); edtEmail = (EditText) findViewById(_email); edtHomePage = (EditText) findViewById(_home_page); edtMemo = (EditText) findViewById(_memo); } /** * 注册按钮单击事件处理⽅法 * * @param view */ public void doRegister(View view) { // 获取⽤户输⼊的数据 String strName = t().toString(); String strGender = t().toString(); String strAge = t().toString(); String strPhone = t().toString(); String strEmail = t().toString(); String strHomePage = t().toString(); String strMemo = t().toString(); // 将输⼊的各项数据打包 Bundle bundle = new Bundle(); ing("name", strName); ing("gender", strGender); ing("age", strAge); ing("phone", strPhone); ing("email", strEmail); ing("home_page", strHomePage); ing("memo", strMemo); // 创建意图,指明起始窗⼝与⽬标窗⼝ Intent intent = new Intent(,); // 携带数据包 ras(bundle); // 按意图启动窗⼝ startActivity(intent); } /** * 取消按钮单击事件处理⽅法 * * @param view */ public void doCancel(View view) { finish(); }}8.接下来是⽂件package gistration;import ty;import ;import ;import ew;public class InformationActivity extends Activity { private TextView tvName; private TextView tvGender; private TextView tvAge; private TextView tvPhone; private TextView tvEmail; private TextView tvHomePage; private TextView tvMemo; @Override protected void onCreate(Bundle savedInstanceState) { te(savedInstanceState); // 利⽤布局⽂件设置⽤户界⾯ setContentView(ty_information); // 通过资源标识获得控件⽰例 tvName = (TextView) findViewById(_name); tvGender = (TextView) findViewById(_gender); tvAge = (TextView) findViewById(_age); tvPhone = (TextView) findViewById(_phone); tvEmail = (TextView) findViewById(_email); tvHomePage = (TextView) findViewById(_home_page); tvMemo = (TextView) findViewById(_memo); // 获得意图 Intent intent = getIntent(); if (intent != null) { // 获得意图携带的数据包 Bundle bundle = ras(); // 从数据包⾥按键取值 String strName = ing("name"); String strGender = ing("gender"); String strAge = ing("age"); String strPhone = ing("phone"); String strEmail = ing("email"); String strHomePage = ing("home_page"); String strMemo = ing("memo"); // 设置各个标签的内容 t("姓名:" + strName); t("性别:" + strGender); t("年龄:" + strAge); t("电话:" + strPhone); t("邮箱:" + strEmail); t("主页:" + strHomePage); t("备注:" + strMemo); } }}我们的代码在这⾥就结束了,接下来是效果图,喜欢的朋友可以⾃⼰拿去改善,有不懂得还可以私聊我,我将会为你解答软件界⾯输⼊数据,这⾥的数据是我随便输⼊的传送效果如图好了,这个⼩案例到这⾥就结束了,感谢⼤家花时间来浏览,再见!
发布者:admin,转转请注明出处:http://www.yc00.com/xiaochengxu/1689217074a222418.html
评论列表(0条)