今天需求要做一个所有app都有的登录界面,正好巩固一下我们之前学的基础布局知识。

先来看下效果图
1.布局的xml文件
<?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" android:background="#2197db" > <ImageView android:id="@+id/loginbutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginTop="40dp" android:src="@drawable/login_pic"/> <LinearLayout android:id="@+id/input" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/loginbutton" android:layout_marginLeft="28dp" android:layout_marginRight="28dp" android:background="#fff" android:orientation="vertical"> <LinearLayout android:layout_width="fill_parent" android:layout_height="44dp" android:background="#fff" android:gravity="center_vertical" android:orientation="horizontal" > <EditText android:id="@+id/userId" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1" android:background="@null" android:imeOptions="actionDone" android:textSize="16sp" android:ems="10" android:hint="请输入用户名" > </EditText> <Button android:id="@+id/button_bar" android:layout_width="20dp" android:layout_height="20dp" android:layout_marginRight="8dp" android:layout_marginLeft="1dp" android:background="@drawable/login_input_arrow" /> </LinearLayout> <View android:layout_width="fill_parent" android:layout_height="1.0px" android:layout_marginLeft="1.0px" android:layout_marginRight="1.0px" android:background="#ffc0c3c4" /> <EditText android:id="@+id/pass" android:layout_width="fill_parent" android:layout_height="44.0dip" android:background="#00ffffff" android:gravity="center_vertical" android:inputType="textPassword" android:maxLength="16" android:maxLines="1" android:textColor="#ff1d1d1d" android:textColorHint="#ff666666" android:textSize="16.0sp" android:hint="请输入密码" /> </LinearLayout> <Button android:id="@+id/loginBtn" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/input" android:layout_marginTop="10dp" android:background="#3aadfd" android:text="登 录" android:textColor="#ffffff" android:textSize="18dp" android:layout_centerHorizontal="true" android:layout_marginLeft="28dp" android:layout_marginRight="28dp"/> <TextView android:text="" android:layout_width="wrap_content" android:layout_below="@+id/loginBtn" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:id="@+id/promptText" android:textColor="#ff0000" android:layout_marginTop="10dp" android:textSize="18sp"/> </RelativeLayout>
2.java部分代码
public class LoginActivity extends Activity implements View.OnClickListener{
private static final String TAG = "login";
Button loginBtn = null;
EditText useridEt = null;
EditText passEt = null;
TextView promptText = null;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
loginBtn = (Button) findViewById(R.id.loginBtn);
loginBtn.setOnClickListener(this);
useridEt = (EditText) findViewById(R.id.userId);
passEt = (EditText) findViewById(R.id.pass);
promptText = (TextView) findViewById(R.id.promptText);
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.connectTimeout(10000L, TimeUnit.MILLISECONDS)
.readTimeout(10000L, TimeUnit.MILLISECONDS)
.build();
OkHttpUtils.initClient(okHttpClient);
@Override
public void onClick(View v) {
String userid = useridEt.getText().toString().trim();
String pass = passEt.getText().toString().trim();
if(userid.equals("")){
promptText.setText(R.string.userIdError);
return ;
}
if(pass.equals("")){
promptText.setText(R.string.passError);
return ;
}
WebConstant.digest = ("Basic " + new String(Base64.encode((userid + ':' + pass).getBytes(), Base64.DEFAULT))).replace("\n", "");
String url = WebConstant.REQUESTPATH+"/users/" + userid+"?getAll=true";
OkHttpUtils.get()
.url(url).addHeader("Authorization", WebConstant.digest).addHeader("Accept-Language","zh-CN")
.build().execute(new Callback()
{
@Override
public String parseNetworkResponse(Response response, int id) throws Exception {
String string = response.body().string();
JSONObject jsonObj = new JSONObject(string);
if(jsonObj.get("userName")!=null){
WebConstant.userId = (String)jsonObj.get("userId");
WebConstant.userName = (String)jsonObj.get("userName");
return (String) jsonObj.get("userName");
}
return null;
}
@Override
public void onError(Call call, Exception e, int id) {
WebConstant.digest = null;
promptText.setText(R.string.loginError);
Log.i(TAG,e.getMessage());
e.printStackTrace();
}
@Override
public void onResponse(Object response, int id) {
promptText.setText(R.string.loginSuccess+" "+response);
Intent intent = new Intent();
LoginActivity.this.setResult(WebConstant.RESULT_OK, intent);
LoginActivity.this.finish();
}
});
}
}
简单的登录,用户名密码验证。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
# Android
# app
# 登录界面
# Android Studio实现登录界面功能
# Android实现登录界面的注册功能
# Android登录界面的实现代码分享
# Android实现注册登录界面的实例代码
# Android设计登录界面、找回密码、注册功能
# 功能强大的登录界面Android实现代码
# Android属性动画实现炫酷的登录界面
# Android开发实例之登录界面的实现
# Android QQ登录界面绘制代码
# Android Studio实现简易登录界面制作
# 请输入
# 要做
# 大家多多
# actionDone
# textSize
# imeOptions
# layout_weight
# null
# hint
# finish
# sp
# ems
# userId
# orientation
# vertical
# fff
# layout_marginRight
# fill_parent
# horizontal
# EditText
相关文章:
h5网站制作工具有哪些,h5页面制作工具有哪些?
如何用低价快速搭建高质量网站?
如何在IIS7上新建站点并设置安全权限?
家庭建站与云服务器建站,如何选择更优?
香港服务器部署网站为何提示未备案?
如何在Golang中使用encoding/gob序列化对象_存储和传输数据
唐山网站制作公司有哪些,唐山找工作哪个网站最靠谱?
制作证书网站有哪些,全国城建培训中心证书查询官网?
Java解压缩zip - 解压缩多个文件或文件夹实例
c++怎么实现高并发下的无锁队列_c++ std::atomic原子变量与CAS操作【详解】
如何快速搭建自助建站会员专属系统?
如何零基础开发自助建站系统?完整教程解析
网站专业制作公司,网站编辑是做什么的?好做吗?工作前景如何?
企业微网站怎么做,公司网站和公众号有什么区别?
做企业网站制作流程,企业网站制作基本流程有哪些?
css网站制作参考文献有哪些,易聊怎么注册?
专业制作网站的公司哪家好,建立一个公司网站的费用.有哪些部分,分别要多少钱?
制作网站的过程怎么写,用凡科建站如何制作自己的网站?
如何快速上传自定义模板至建站之星?
建站上市公司网站建设方案与SEO优化服务定制指南
如何解决ASP生成WAP建站中文乱码问题?
网站制作模板下载什么软件,ppt模板免费下载网站?
台州网站建设制作公司,浙江手机无犯罪记录证明怎么开?
C#怎么创建控制台应用 C# Console App项目创建方法
湖州网站制作公司有哪些,浙江中蓝新能源公司官网?
如何用手机制作网站和网页,手机移动端的网站能制作成中英双语的吗?
品牌网站制作公司有哪些,买正品品牌一般去哪个网站买?
怀化网站制作公司,怀化新生儿上户网上办理流程?
,石家庄四十八中学官网?
如何在腾讯云服务器上快速搭建个人网站?
如何有效防御Web建站篡改攻击?
网站制作大概多少钱一个,做一个平台网站大概多少钱?
广州网站制作的公司,现在专门做网站的公司有没有哪几家是比较好的,性价比高,模板也多的?
c++如何打印函数堆栈信息_c++ backtrace函数与符号名解析【方法】
如何通过VPS搭建网站快速盈利?
实惠建站价格推荐:2025年高性价比自助建站套餐解析
头像制作网站在线观看,除了站酷,还有哪些比较好的设计网站?
如何配置IIS站点权限与局域网访问?
如何通过宝塔面板实现本地网站访问?
武清网站制作公司,天津武清个人营业执照注销查询系统网站?
如何配置WinSCP新建站点的密钥验证步骤?
零服务器AI建站解决方案:快速部署与云端平台低成本实践
油猴 教程,油猴搜脚本为什么会网页无法显示?
导航网站建站方案与优化指南:一站式高效搭建技巧解析
香港网站服务器数量如何影响SEO优化效果?
太原网站制作公司有哪些,网约车营运证查询官网?
制作网站的软件免费下载,免费制作app哪个平台好?
制作网站建设的公司有哪些,网站建设比较好的公司都有哪些?
如何快速登录WAP自助建站平台?
建站168自助建站系统:快速模板定制与SEO优化指南
*请认真填写需求信息,我们会在24小时内与您取得联系。