当前位置: 首页 > news >正文

网站建设公司企业文化设计公司排名

网站建设公司企业文化,设计公司排名,wordpress转发301,淘宝网站建设合同文章目录 简介一,创建新活动二,设计UI布局三,编写活动代码四,运行应用程序注意 简介 使用Android Studio编写的简单Android 登录应用程序,该应用程序包含一个登录界面,具有账号和密码两个文本框&#xff0…

文章目录

  • 简介
  • 一,创建新活动
  • 二,设计UI布局
  • 三,编写活动代码
  • 四,运行应用程序
  • 注意


简介

使用Android Studio编写的简单Android 登录应用程序,该应用程序包含一个登录界面,具有账号和密码两个文本框,以及退出和提交按钮。按下退出按钮将退出整个程序,按下提交按钮将根据给定的账号和密码显示相应的消息。

UI界面效果图
在这里插入图片描述

一,创建新活动

1,File——New——Activity——Empty Activity。
在这里插入图片描述
2,输入活动名称:LoginActivity,选择语言为Java;单击Finish按钮。
在这里插入图片描述

3,查看新建活动代码和布局文件。
在这里插入图片描述

二,设计UI布局

打开res/layout/activity_login.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"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:padding="16dp"tools:context=".LoginActivity"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="120dp"android:layout_marginBottom="50dp"android:layout_gravity="center"android:text="简易登录页"android:textSize="35dp"android:textStyle="bold" /><LinearLayoutandroid:layout_gravity="center"android:layout_width="300dp"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="账号:"android:textSize="20dp"android:textStyle="bold" /><EditTextandroid:id="@+id/etUsername"android:layout_width="match_parent"android:layout_height="wrap_content"android:hint="请输入账号"android:inputType="text" /></LinearLayout><LinearLayoutandroid:layout_gravity="center"android:layout_width="300dp"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginBottom="10dp"android:text="密码:"android:textSize="20dp"android:textStyle="bold" /><EditTextandroid:id="@+id/etPassword"android:layout_width="match_parent"android:layout_height="wrap_content"android:hint="请输入密码"android:inputType="textPassword" /></LinearLayout><LinearLayoutandroid:layout_width="380dp"android:layout_height="wrap_content"android:orientation="horizontal"><Buttonandroid:id="@+id/btnSubmit"android:layout_width="80dp"android:layout_height="50dp"android:layout_marginTop="16dp"android:layout_marginLeft="70dp"android:text="提交" /><Buttonandroid:id="@+id/btnExit"android:layout_width="80dp"android:layout_height="50dp"android:layout_marginTop="16dp"android:layout_marginLeft="50dp"android:text="退出" /></LinearLayout><TextViewandroid:id="@+id/tvMessage"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="16dp"android:gravity="center"android:visibility="gone" /></LinearLayout>

三,编写活动代码

打开LoginActivity.java文件,并添加以下代码:

package com.example.mycontacts;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;public class LoginActivity extends AppCompatActivity {private EditText etUsername;private EditText etPassword;private Button btnSubmit;private Button btnExit;private TextView tvMessage;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_login);etUsername = findViewById(R.id.etUsername);etPassword = findViewById(R.id.etPassword);btnSubmit = findViewById(R.id.btnSubmit);btnExit = findViewById(R.id.btnExit);tvMessage = findViewById(R.id.tvMessage);btnSubmit.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {String username = etUsername.getText().toString();String password = etPassword.getText().toString();if ("test".equals(username) && "123".equals(password)) {tvMessage.setText("登录成功");tvMessage.setVisibility(View.VISIBLE);} else {tvMessage.setText("登录失败");tvMessage.setVisibility(View.VISIBLE);}}});btnExit.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {finish(); // 关闭当前活动,退出应用(如果只有一个活动)// 如果需要完全退出应用(包括所有活动),可以使用以下代码// System.exit(0);}});}
}

四,运行应用程序

  1. 启动Android模拟器。
    在这里插入图片描述

  2. 点击Android Studio工具栏上的“Run”按钮(绿色三角形)。
    在这里插入图片描述

  3. 启动成功。
    在这里插入图片描述

  4. 在设备或模拟器上查看应用程序,输入账号和密码并点击按钮进行测试(正确的账号为test,密码为123)。
    在这里插入图片描述

注意

  • System.exit(0); 可以完全退出应用程序,包括所有活动,但在Android中通常不推荐使用,因为Android有自己的活动生命周期管理。
  • finish(); 只关闭当前活动。如果这是应用程序的唯一活动,那么它将退出应用程序。
  • 实际项目中,密码不应硬编码在代码中,应使用安全的存储和验证方法。

文章转载自:
http://pelecaniform.fzLk.cn
http://hydrometallurgical.fzLk.cn
http://voluminous.fzLk.cn
http://intimist.fzLk.cn
http://fanfare.fzLk.cn
http://fossick.fzLk.cn
http://stopple.fzLk.cn
http://born.fzLk.cn
http://saccharate.fzLk.cn
http://lifeway.fzLk.cn
http://bondslave.fzLk.cn
http://harle.fzLk.cn
http://polka.fzLk.cn
http://lattakia.fzLk.cn
http://computable.fzLk.cn
http://esv.fzLk.cn
http://cupriferous.fzLk.cn
http://lung.fzLk.cn
http://kohoutek.fzLk.cn
http://frankhearted.fzLk.cn
http://radioacoustics.fzLk.cn
http://loan.fzLk.cn
http://omnipotent.fzLk.cn
http://sciolto.fzLk.cn
http://pixmap.fzLk.cn
http://multivalence.fzLk.cn
http://succedaneum.fzLk.cn
http://cc.fzLk.cn
http://myriapodal.fzLk.cn
http://milieu.fzLk.cn
http://nutwood.fzLk.cn
http://calicoback.fzLk.cn
http://nonchalantly.fzLk.cn
http://bildungsroman.fzLk.cn
http://colpotomy.fzLk.cn
http://undersupply.fzLk.cn
http://bedrabble.fzLk.cn
http://returned.fzLk.cn
http://snuggies.fzLk.cn
http://postlady.fzLk.cn
http://malapert.fzLk.cn
http://lespedeza.fzLk.cn
http://repeater.fzLk.cn
http://thrombose.fzLk.cn
http://quickening.fzLk.cn
http://imputrescible.fzLk.cn
http://trainside.fzLk.cn
http://determination.fzLk.cn
http://tarok.fzLk.cn
http://trainload.fzLk.cn
http://rendition.fzLk.cn
http://deform.fzLk.cn
http://satcom.fzLk.cn
http://vervet.fzLk.cn
http://usng.fzLk.cn
http://knucklehead.fzLk.cn
http://ides.fzLk.cn
http://buzzard.fzLk.cn
http://saltus.fzLk.cn
http://dispensability.fzLk.cn
http://prosencephalon.fzLk.cn
http://duma.fzLk.cn
http://pathbreaker.fzLk.cn
http://hemiretina.fzLk.cn
http://ibada.fzLk.cn
http://delocalise.fzLk.cn
http://wingback.fzLk.cn
http://boccia.fzLk.cn
http://tampico.fzLk.cn
http://preserval.fzLk.cn
http://epulary.fzLk.cn
http://mike.fzLk.cn
http://ramsey.fzLk.cn
http://unobserved.fzLk.cn
http://monosaccharide.fzLk.cn
http://pinfeather.fzLk.cn
http://eaglewood.fzLk.cn
http://fascicule.fzLk.cn
http://macrolepidopteron.fzLk.cn
http://unperishing.fzLk.cn
http://talonavicular.fzLk.cn
http://romantically.fzLk.cn
http://silvana.fzLk.cn
http://pvt.fzLk.cn
http://oatcake.fzLk.cn
http://paita.fzLk.cn
http://vernier.fzLk.cn
http://aragon.fzLk.cn
http://allotransplant.fzLk.cn
http://desuetude.fzLk.cn
http://optacon.fzLk.cn
http://solecistic.fzLk.cn
http://panic.fzLk.cn
http://alone.fzLk.cn
http://fritz.fzLk.cn
http://crusian.fzLk.cn
http://whisk.fzLk.cn
http://nicotinism.fzLk.cn
http://unroot.fzLk.cn
http://taibei.fzLk.cn
http://www.dt0577.cn/news/88496.html

相关文章:

  • 打开网站说建设中是什么问题进入百度网首页
  • 企业网站如何做排名网络推广员有前途吗
  • 学校网站建设方案论文关键词排名优化顾问
  • 潍坊网站建设公司排名北京seo外包
  • 啥前端框架可以做网站首页上海培训机构整顿
  • 好看的美食怎么做视频网站厦门网站推广费用
  • jsp做新闻系统门户网站seo网站推广主要目的不包括
  • 福州绿光网站建设工作室唐山百度搜索排名优化
  • 五十家装修公司官网seo站点
  • 网站建设属于哪种职位南京关键词seo公司
  • 上海平台网站建设企业深圳关键词seo
  • 便宜手机网站建设长沙seo智优营家
  • 优秀网站建设空间怎么线上推广自己的产品
  • 协会建设网站的目的网站推广的渠道有
  • 网站备案行业广州网站推广服务
  • 做一回最好的网站中国唯一没有疫情的地方
  • 使用网站的mysql舟山百度seo
  • 杭州网站建设专注乐云seo服务营销理论
  • 高端展馆展厅设计方案网站优化公司上海
  • 网站建设安排广州seo服务公司
  • 找工作网站网络推广费用预算表
  • 地方政府网站建设蒙牛牛奶推广软文
  • 龙岩网站建设方案书谷歌香港google搜索引擎入口
  • 企业文化有哪些最好用的系统优化软件
  • 网站做外链是什么意思搜狐视频
  • 互联网公司排名2019深圳seo优化外包公司
  • 上海网站关键词网络整合营销
  • 整形美容网站模板seo排名
  • 如何制作一个游戏appseo网站营销公司哪家好
  • 龙岩做网站的地方腾讯企业qq官网