怎么用Android做登录界面,利用Android怎么制作一个APP登录界面
利用Android怎么制作一个APP登录界面
发布时间:2020-12-02 17:09:10
来源:亿速云
阅读:79
作者:Leah
这期内容当中小编将会给大家带来有关利用Android怎么制作一个APP登录界面,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
1.布局的xml文件
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#2197db"
>
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"/>
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">
android:layout_width="fill_parent"
android:layout_height="44dp"
android:background="#fff"
android:gravity="center_vertical"
android:orientation="horizontal" >
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="请输入用户名"
>
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"
/>
android:layout_width="fill_parent"
android:layout_height="1.0px"
android:layout_marginLeft="1.0px"
android:layout_marginRight="1.0px"
android:background="#ffc0c3c4" />
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="请输入密码"
/>
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"/>
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"/>
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做登录界面,利用Android怎么制作一个APP登录界面相关推荐
- 【Android Studio学习】第一篇、制作一个拥有登录和注册功能的简易APP
目录 第一部分.前言 1.目标效果 2.准备知识 第二部分.详细步骤 1.新建Empty工程 2.添加资源文件 3.搭建注册界面 4.搭建登录界面 5.编写注册界面和登录界面的代码 6.设置APP初 ...
- python制作软件界面_使用Python制作一个带GUI界面的词云自动生成工具(一)
在现实生活中你可能会遇到这种情况:想知道一篇论文中哪个词语最多,哪些词语最少(以此判断文章的主要内容):想知道一部小说中哪一个人物出现的次数最多(当然,出现次数最多的那个人也不一定是主脚):想知道一部 ...
- php微信自动登录,利用php怎么实现一个自动登录微信并获取昵称的功能
利用php怎么实现一个自动登录微信并获取昵称的功能 发布时间:2021-02-18 14:55:53 来源:亿速云 阅读:58 作者:Leah 这篇文章将为大家详细讲解有关利用php怎么实现一个自动登 ...
- html登录页面用idea,利用IDEA怎么制作一个登录注册页面
利用IDEA怎么制作一个登录注册页面 发布时间:2020-12-19 14:02:09 来源:亿速云 阅读:186 作者:Leah 利用IDEA怎么制作一个登录注册页面?很多新手对此不是很清楚,为了帮 ...
- 如何利用laragon框架制作一个简单的应用?
如何利用laragon框架制作一个简单的应用? 一.搭建环境 1. 安装Laragon 1.1 打开安装包用的语言 选择自己习惯用的语言 1.2 选择安装地址 1.3 选择Next,开始install ...
- 利用51单片机制作一个秒表的详细过程
利用51单片机制作一个秒表的详细过程 前面的话: 和很多朋友一样,在学51单片机的过程中我们肯定会涉及到制作一个秒表,牵涉到把单片机的多个部分组合起来使用,这对于我们初学者来说可能显得有些困难,我同大 ...
- 用html5和js制作一个游戏启动界面(html5游戏开发一)、
制作一个游戏启动界面,用户点击屏幕进入游戏主界面 首先建立一个html文档,在body里面添加一个游戏容器,再将主菜单界面元素添加到添加到游戏容器里面. <div id="game&q ...
- php制作404,利用thinkphp怎么制作一个404跳转页面
利用thinkphp怎么制作一个404跳转页面 发布时间:2020-12-14 15:46:55 来源:亿速云 阅读:97 作者:Leah 本篇文章给大家分享的是有关利用thinkphp怎么制作一个4 ...
- 制作一个银行卡登录系统
制作一个银行卡登录系统 {"expire_date":"2021-01-01","id":"1234","st ...
最新文章
- Java Json API:Gson使用简单入门
- vlan配置实例详解_【精品网络干货】二层MSTP防环技术详解
- boost::type_erasure::param相关的测试程序
- 2299 Ultra-QuickSort(归并)
- TCP粘包问题分析和解决(全)
- c语言运算符ppt,C语言知识学习运算符.ppt
- 买铅笔(洛谷-P1909)
- Win10启动项设置在哪里
- 2018校招笔试真题汇总
- [生存志] 第71节 阖闾五战入郢
- linux有什么好的软件,Linux国产软件大盘点
- xinxin - 初步学习tkinter
- 小米usb测试软件,你还在用USB传文件?小米10系列USB详细测试——《小米10十大槽点》番外 图文版...
- 第三届长沙 · 中国 1024 程序员节:共迎算力新时代,开源新未来
- 到底咋做,才能业务财务真的一体化
- 记录生活账本,查看账目清晰更可查
- 前端时间格式2020-11-18T22:42:48.000+00:00 转化成正常格式
- 蜘蛛爬行html语言的顺序,搜索引擎蜘蛛爬行的规律是什么?
- php 对全角字符的过滤,php在做敏感词过滤时怎么解决用特殊符号分割、简繁体、半角全角,来绕开过滤的问题?...
- 阿里规范-为什么不允许魔法值(即未经定义的常量)出现在代码中?