标签:Toast 界面 第三周 点击 按钮 import View
1.创建3个界面
第一个界面有3个button
第二个界面有单选按钮 学历:初中 高中 专科 本科
第三个界面有5个复选框 学过哪些课程
Java
Ios
Android
Html
Jsp
把第二个界面设置为启动界面
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".Demo1Activity" android:orientation="vertical"> <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="按钮1" android:onClick="click1"/> <Button android:id="@+id/button2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="按钮2"/> <Button android:id="@+id/button3" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="按钮3"/> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".Demo2Activity" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="你的学历是什么?" android:textColor="#0A0A0A"/> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="初中" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="高中" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="专科" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="本科"/> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".Demo3Activity" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="你学过哪些课程" android:textColor="#000000"/> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="JAVA"/> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="IOS"/> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="ANDROID"/> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="HTML"/> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="JSP"/> </LinearLayout>
2.在界面1上设置按钮点击事件
按钮1用onclick方式
按钮2和按钮3用监听方式
点击后用Toast弹出 按钮xxx被点击
package com.example.myapplication; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.Toast; public class Demo1Activity extends AppCompatActivity { private Button btn2; private Button btn3; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_demo1); btn2=findViewById(R.id.button2); btn2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(Demo1Activity.this, "按钮2被点击", Toast.LENGTH_SHORT).show(); } }); btn3=findViewById(R.id.button3); btn3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(Demo1Activity.this, "按钮3被点击", Toast.LENGTH_SHORT).show(); } }); } public void click1(View view){ Toast.makeText(this, "按钮1被点击", Toast.LENGTH_SHORT).show(); } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".Demo1Activity" android:orientation="vertical"> <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="按钮1" android:onClick="click1"/> <Button android:id="@+id/button2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="按钮2"/> <Button android:id="@+id/button3" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="按钮3"/> </LinearLayout>
3.设计布局界面(详见QQ群)
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".Main2Activity" android:orientation="vertical"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/xiaobiaodayin" android:layout_gravity="center" android:layout_marginTop="100dp"/> <EditText android:layout_width="match_parent" android:layout_height="80dp" android:hint="请输入手机号/邮箱" android:layout_marginTop="50dp" android:gravity="center" /> <EditText android:layout_width="match_parent" android:layout_height="80dp" android:hint="请输入密码" android:gravity="center" android:drawableRight="@drawable/yanjingbi" android:drawablePadding="10dp" android:layout_marginTop="10dp"/> <Button android:layout_width="400dp" android:layout_height="50dp" android:text="登录" android:textColor="#FFFFFF" android:gravity="center" android:layout_gravity="center" android:layout_marginTop="30dp" android:background="@drawable/btn_2" /> <Button android:layout_width="400dp" android:layout_height="50dp" android:text="不注册,跳过登录" android:textColor="#FFFFFF" android:gravity="center" android:layout_gravity="center" android:background="@drawable/btn_3" android:layout_marginTop="10dp" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="注册账号" android:layout_margin="10dp" android:layout_alignParentLeft="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="注册账号" android:layout_margin="10dp" android:layout_alignParentRight="true" /> </RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/weixin" android:layout_alignParentLeft="true" android:layout_marginLeft="100dp"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/pingguo" android:layout_centerInParent="true"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/qq" android:layout_alignParentRight="true" android:layout_marginRight="100dp"/> </RelativeLayout> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <CheckBox android:id="@+id/z1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="50dp" /> <TextView android:id="@+id/z2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="已阅读并同意" android:layout_toRightOf="@+id/z1" android:padding="5dp"/> <TextView android:id="@+id/z3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="《用户协议》" android:textColor="#FA0606" android:layout_toRightOf="@id/z2" android:padding="5dp"/> <TextView android:id="@+id/z4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="和" android:layout_toRightOf="@id/z3" android:padding="5dp"/> <TextView android:id="@+id/z5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="《隐私政策》" android:textColor="#FA0606" android:layout_toRightOf="@id/z4" android:padding="5dp"/> </RelativeLayout> </LinearLayout>
标签:Toast,界面,第三周,点击,按钮,import,View 来源: https://www.cnblogs.com/songchi/p/15229431.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。