当前位置:网站首页>andorid实例-简单登录布局
andorid实例-简单登录布局
2020-11-09 17:46:00 【ZHAO_JH】
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#36A4D9"
android:fitsSystemWindows="false"
android:gravity="center|top"
android:orientation="vertical"
tools:context=".MainActivity">
<!-- 通知栏留空变透明需要留空-->
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:textSize="30sp">
</TextView>
<!--标题-->
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:gravity="center"
android:text="简易登录页面"
android:textColor="#fff"
android:textSize="30sp">
</TextView>
<!-- 用户名和密码信息-->
<RelativeLayout
android:layout_width="356dp"
android:layout_height="300dp"
android:background="#fff">
<!-- 用户名信息-->
<TextView
android:id="@+id/user_text"
android:layout_width="96dp"
android:layout_height="50dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="50dp"
android:background="#36A4D9"
android:gravity="center"
android:text="用户名:"
android:textColor="#fff"
android:textSize="20sp">
</TextView>
<EditText
android:id="@+id/user_info"
android:layout_width="203dp"
android:layout_height="50dp"
android:layout_marginTop="50dp"
android:layout_toRightOf="@id/user_text"
android:hint="请输入用户名">
</EditText>
<!-- 密码信息-->
<TextView
android:id="@+id/pwd_text"
android:layout_width="96dp"
android:layout_height="50dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="110dp"
android:background="#36A4D9"
android:gravity="center"
android:text="密 码:"
android:textColor="#fff"
android:textSize="20sp">
</TextView>
<EditText
android:id="@+id/pwd_info"
android:layout_width="203dp"
android:layout_height="50dp"
android:layout_marginTop="110dp"
android:layout_toRightOf="@id/user_text"
android:hint="请输入密码">
</EditText>
<!-- 记住密码-->
<CheckBox
android:id="@+id/remember_info"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="170dp"
android:text="记住用户名密码"
android:textColor="#000"
android:textSize="16sp">
</CheckBox>
<!-- 登录按钮-->
<Button
android:id="@+id/login_button"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="230dp"
android:background="#36A4D9"
android:text="登 录"
android:textColor="#fff"
android:textSize="26sp">
</Button>
</RelativeLayout>
<!-- 版权声明信息-->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:layout_weight="1"
android:gravity="center|bottom"
android:text="*此应用属个人测试,未经允许不得发布*"
android:textColor="#fff"
android:textSize="14sp">
</TextView>
</LinearLayout>
MainActivity.java
package com.example.myapplication;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.app.Activity;
import android.view.*;
import android.widget.*;
public class MainActivity extends Activity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
// 保存Activity的状态 11
super.onCreate(savedInstanceState);
// 加载视图
setContentView(R.layout.activity_main);
// 安卓沉浸式设置透明状态栏
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
| WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
window.setNavigationBarColor(Color.TRANSPARENT);
}
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window window = getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
// 获取按钮对象
Button btnshow = findViewById(R.id.login_button);
//直接写个this绑定事件
btnshow.setOnClickListener(this);
}
// 点击按钮方法
@Override
public void onClick(View v) {
// 获取登录页面数据对象
EditText user_obj = findViewById(R.id.user_info);
EditText pwd_obj = findViewById(R.id.pwd_info);
CheckBox remember_obj = findViewById(R.id.remember_info);
Toast.makeText(getApplicationContext(), "您输入的用户名是:【"+user_obj.getText() + "】密码是:【"+pwd_obj.getText()+"】密码记住情况【"+remember_obj.isChecked()+"】" , Toast.LENGTH_SHORT).show();
}
}
版权声明
本文为[ZHAO_JH]所创,转载请带上原文链接,感谢
https://my.oschina.net/zhaojunhui/blog/4710220
边栏推荐
- 【STM32F429】第6章 ThreadX GUIX上手之STM32F429 DMA2D加速
- 函数计算进阶-IP查询工具开发
- The basic principle of MRAM
- The selection of wire displacement encoder needs the guidance of precise electronics
- flask图书CURD小项目
- How to design and implement storage QoS?
- [invite you to vote] who is the key driver behind these big open source events in 2020?
- Chrome浏览器 js 关闭窗口失效解决方法
- Function calculation advanced IP query tool development
- Toolkit Pro helps interface development: shorten the project development cycle and quickly realize GUI with modern functional area style
猜你喜欢
Implement printf function by yourself
数据库执行truncate table CM_CHECK_ITEM_HIS怎么恢复
Colleague notes - small program entry point
Avoid pitfall guide for cloud integration - Android push
CentOS查看CPU核心数及cpuinfo解析
Super discount, cloud server 88 yuan seconds
SEO解决方案制定,如何脱离杯弓蛇影?
同事笔记-小程序入坑点
详解Git
The database executes truncate table cm_ CHECK_ ITEM_ How does his recover
随机推荐
Application of pull wire displacement sensor in slope cracks
Detailed explanation of ipfsapp development method of biaofen IPFs mining machine app software development software
如何设计并实现存储QoS?
Function calculation advanced IP query tool development
5 minutes get I use GitHub's five-year summary of these complaints!
Mit6.824 distributed system course translation & learning notes (3) GFS
谈谈敏捷开发概念和迭代开发方案
从硅谷到小米,崔宝秋的25年开源人生
flask图书CURD小项目
电商/直播速看!双11跑赢李佳琦就看这款单品了!
CentOS view the number of CPU cores and cpuinfo analysis
EasyExcel根据筛选列导出(中间不空列,顺序可调整)
揭秘在召唤师峡谷中移动路径选择逻辑?
Source code analysis of serilog -- implementation of sink
Toolkit Pro helps interface development: shorten the project development cycle and quickly realize GUI with modern functional area style
ABBYY FineReader 15新增编辑页面布局功能
. net report builder stimulsoft Reports.Net Release the latest version of v2020.5!
The basic principle of MRAM
脑机接口先驱炮轰马斯克:“他走的是一条死胡同,说的话我一个字都不同意”
Knowledge mapping 1.1 -- starting from NER