标签:name 软件开发 tv private intent 跳转 Intent Android id
Android 软件开发,简易的登录界面与跳转效果
总览:
页面代码
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/cmyk"
>
/><!-- android:background 表示背景,可以设置为图案或颜色 -->
/><!-- match_parent 表示宽高为父类的大小 -->
/><!-- wrap_content 表示由自带的内容物,将宽和高撑大 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:background="#ffffff"
>
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:textSize="18dp"
android:textColor="#000"
android:padding="10dp"
android:text="账号:"/>
<EditText
android:id="@+id/uname_et"
android:hint="请输入账号"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_weight="1"
android:background="@null"
android:lines="1"
android:maxLines="1"
android:scrollHorizontally="false"
android:maxLength="20"
/>
/><!-- scrollHorizontally 表示在内容溢出时,有无滚动条 -->
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:background="#ffffff"
>
<TextView
android:id="@+id/tv_psw"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:textSize="18dp"
android:textColor="#000"
android:padding="10dp"
android:text="密码:"/>
<EditText
android:id="@+id/psd_et"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:inputType="textPassword"
android:layout_weight="1"
android:lines="1"
android:maxLines="1"
android:background="@null"
android:maxLength="20"
/>
/><!-- android:background="@null" 可以取消编辑文本的下划线 -->
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
>
<Button
android:id="@+id/login_but"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#A08FD5"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textColor="#ffffff"
android:textSize="15dp"
android:text="登录"/>
/><!-- layout_weight 的属性值代表在其本身的宽高设置完成后,会将父元素内剩余的宽高按照layout_weight 的属性值按比例再分配-->
<Button
android:id="@+id/register_but"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#EEB0AC"
android:textColor="#ffffff"
android:layout_marginLeft="2dp"
android:layout_marginRight="10dp"
android:textSize="15dp"
android:text="注册"/>
</LinearLayout>
</LinearLayout>
activity_main2.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="账号:"
android:textSize="24dp"
android:id="@+id/tv_name"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密码:"
android:textSize="24dp"
/>
</LinearLayout>
</LinearLayout>
activity_main3.xml
<?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="wrap_content"
android:orientation="vertical"
tools:context=".Main3Activity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:textColor="#A08FD5"
android:text="账  号:"/>
<EditText
android:id="@+id/et_zhang3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="请输入注册账号"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:textColor="#A08FD5"
android:text="密  码:"/>
<EditText
android:layout_width="1000dp"
android:layout_height="wrap_content"
android:id="@+id/ed_mima"
android:inputType="textPassword"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:textColor="#A08FD5"
android:text="邮  箱:"/>
<EditText
android:layout_width="1000dp"
android:layout_height="wrap_content"
android:id="@+id/ed_youxiang"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/rg_but"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_weight="1"
android:background="#FA5C65"
android:text="注  册"/>
</LinearLayout>
</LinearLayout>
逻辑代码
MainActivity.java
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private EditText nameEt;
private EditText psdEt;
private String name,psd;
private Button loginbut,registerbut;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
loginbut.setOnClickListener(this);
registerbut.setOnClickListener(this);
}
private void init(){
nameEt= findViewById(R.id.uname_et);
psdEt=findViewById(R.id.psd_et);
loginbut=findViewById(R.id.login_but);
registerbut=findViewById(R.id.register_but);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.login_but:
name = nameEt.getText().toString().trim();
psd = psdEt.getText().toString().trim();
if (TextUtils.isEmpty(name) || TextUtils.isEmpty(psd)) {
Toast.makeText(MainActivity.this, "信息不能为空", Toast.LENGTH_SHORT).show();
} else {
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
intent.putExtra("name2", name);
intent.putExtra("psd2", psd);
startActivity(intent);
}
break;
case R.id.register_but:
Intent intent = new Intent(MainActivity.this, Main3Activity.class);
startActivity(intent);
break;
}
}
}
Main2Activity.java
public class Main2Activity extends AppCompatActivity {
private TextView tv_name;
private TextView tv_password;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Intent intent = getIntent();
String name2 = intent.getStringExtra("name2");
String psd2=intent.getStringExtra("psd2");
tv_name=findViewById(R.id.tv_name);
tv_password=findViewById(R.id.tv_password);
tv_name.setText("用户名:"+name2);
tv_password.setText("密码"+psd2);
}
}
Main3Activity.java
public class Main3Activity extends AppCompatActivity {
private Button rg3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
rg3=findViewById(R.id.rg_but);
rg3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent ok=new Intent(Main3Activity.this,MainActivity.class);
Toast.makeText(getApplicationContext(), "注册成功", Toast.LENGTH_SHORT).show();
startActivity(ok);
}
});
}
}
页面展示
一些描述
一共有三个界面,每个.xml文件对应一个界面,同时每个界面对应一份.java文件的逻辑代码文件。
.xml文件中,使用了线性布局,同时,线性布局的嵌套,使得能够,横向的显示我的一些标签(比如,横向的两个按钮)。再设置了背景,大小,间距,颜色的一些属性后,界面得以实现。
.java文件一 一对应这.xml界面中的逻辑实现部分,在这里,需要给按钮设置监听器,以监听按钮的动向(是否被点击)。在被点击后,去执行页面跳转的相关功能。
标签:name,软件开发,tv,private,intent,跳转,Intent,Android,id 来源: https://blog.csdn.net/norang/article/details/114857958
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。