- 创建项目:
- 创建activity
- 编写界面和代码
package com.example.exp3;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{ EditText account,password; Button login; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initlogin(); } private void initlogin(){ login=findViewById(R.id.login); account=findViewById(R.id.account); password=findViewById(R.id.password); login.setOnClickListener(this); }
@Override public void onClick(View v) { switch (v.getId()){ case R.id.login: Intent iti=new Intent(this,UIActivity.class); iti.putExtra("account",account.getText().toString() ); iti.putExtra("password",password.getText().toString() ); startActivity(iti); break; } } }
|
package com.example.exp3;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle; import android.widget.TextView;
public class UIActivity extends AppCompatActivity { TextView account,password; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_u_i); initshow(); } private void initshow(){ account=findViewById(R.id.accountshow); password=findViewById(R.id.passwordshow); account.setText(getIntent().getStringExtra("account")); password.setText(getIntent().getStringExtra("password")); } }
|
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/acconuthang" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/accountwo" android:text="账号:" android:textColor="@color/black" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/account" android:layout_alignLeft="@id/accountwo" android:hint="@string/phone" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/passwordhang" android:layout_below="@id/acconuthang" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/passwordwo" android:text="密码:" android:textColor="@color/black" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/password" android:layout_alignLeft="@id/passwordwo" android:hint="请输入密码" android:password="true" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/passwordhang"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/login" android:text="@string/login" android:background="@drawable/login" android:layout_marginLeft="40dp" /> </LinearLayout>
</RelativeLayout>
|
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/acconuthang" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="账号: " android:textColor="@color/black" android:textSize="25dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/accountshow" android:text="账号" android:textColor="@color/black" android:textSize="25dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" 密码: " android:textColor="@color/black" android:textSize="25dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="25dp" android:id="@+id/passwordshow" android:text="密码" android:textColor="@color/black" /> </LinearLayout>
</RelativeLayout>
|
- 运行效果
本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端