iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >Android miniTwitter登录界面开发实例
  • 400
分享到

Android miniTwitter登录界面开发实例

界面Android 2022-06-06 08:06:21 400人浏览 独家记忆
摘要

本文要演示的Android开发实例是如何完成一个Android中的miniTwitter登录界面,下面将分步骤讲解怎样实现图中的界面效果,让大家都能轻松的做出美观的登录界面。

本文要演示的Android开发实例是如何完成一个Android中的miniTwitter登录界面,下面将分步骤讲解怎样实现图中的界面效果,让大家都能轻松的做出美观的登录界面。

先贴上最终要完成的效果图:

miniTwitter登录界面的布局分析

首先由界面图分析布局,基本可以分为三个部分,下面分别讲解每个部分。

第一部分是一个带渐变色背景的LinearLayout布局,关于背景渐变色就不再贴代码了,效果如下图所示:

第二部分,红色线区域内,包括1,2,3,4 如图所示:

红色的1表示的是一个带圆角且背景色为#55FFFFFF(淡蓝色)的RelativeLayout布局,代码如下:


<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="Http://schemas.android.com/apk/res/android"> 
<solid android:color="#55FFFFFF" /> 
<!-- 设置圆角 
注意: bottomRightRadius是左下角而不是右下角 bottomLeftRadius右下角--> 
<corners android:topLeftRadius="10dp" android:topRightRadius="10dp" 
android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp"/> 
</shape> 

solid表示填充色,这里填充的是淡蓝色。corners是设置圆角。

dp (即dip,device independent pixels)设备独立像素:这个和设备硬件有关,一般我们为了支持WVGA、HVGA和QVGA ,不依赖像素。在android上开发的程序将会在不同分辨率的手机上运行。为了让程序外观不至于相差太大,所以引入了dip的概念。比如定义一个矩形10 x 10dip. 在分辨率为160dpi 的屏上,比如G1,正好是10 x 10像素。 而在240 dpi 的屏,则是15 x 15 像素。换算公式为 pixs = dips * (density/160)。density 就是屏的分辨率。

然后RelativeLayou的background引用此drawable,具体RelativeLayout设置如下:


<RelativeLayout 
   android:id="@+id/login_div" 
   android:layout_width="fill_parent" 
   android:layout_height="wrap_content" 
   android:padding="15dip" 
   android:layout_margin="15dip" 
   android:background="@drawable/background_login_div_bg" 
   > 
</RelativeLayout> 

padding 是指内边距(也就是指内容与边框的距离),layout_margin为外边距(它的上一层与边框的距离)。

接下来是区域2,为账号的文本和输入框,首先是账号的文本,代码如下:


<TextView 
  android:id="@+id/login_user_input" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" 
  android:layout_alignParentTop="true" 
  android:layout_marginTop="5dp" 
  android:text="@string/login_label_username" 
  style="@style/nORMalText"/> 

android:layout_alignParentTop 这里表示此TextView的位置处于顶部

android:layout_marginTop="5dp" 这里表示此TextView的边框与RelativeLayout的顶部边框距离有5dp

这里需要对这个TextView设置下字体颜色和字体大小,定义在res/style.xml里面:


<style name="normalText" parent="@android:style/TextAppearance"> 
  <item name="android:textColor">#444</item> 
  <item name="android:textSize">14sp</item> 
</style> 

定义账号的输入框,如下:


<EditText 
android:id="@+id/username_edit" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:hint="@string/login_username_hint" 
android:layout_below="@id/login_user_input" 
android:singleLine="true" 
android:inputType="text"/> 

android:hint 输入框里面的提示文字,android:layout_below这里是设置为在账号的文本框的下面,android:singleLine 为单行输入(即你输入回车的时候不会在换行了),android:inputType这里text表示输入的类型为文本。

区域3是密码文本和输入框,同区域2,代码如下:


<TextView 
  android:id="@+id/login_passWord_input" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" 
  android:layout_below="@id/username_edit" 
  android:layout_marginTop="3Dp" 
  android:text="@string/login_label_password" 
  style="@style/normalText"/> 
<EditText 
  android:id="@+id/password_edit" 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  android:layout_below="@id/login_password_input" 
  android:password="true" 
  android:singleLine="true" 
  android:inputType="textPassword" 
/> 

区域4,登录按钮:


<Button 
  android:id="@+id/signin_button" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" 
  android:layout_below="@id/password_edit" 
  android:layout_alignRight="@id/password_edit" 
  android:text="@string/login_label_signin" 
  android:background="@drawable/blue_button" 
/> 

第三部分:底下的文字和两张图片,分别标记了1,2,3,4:

Android miniTwitter登录界面

区域1:还是一个RelativeLayout,但这里设置的很简单,代码如下:


<RelativeLayout 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content"> 
</RelativeLayout> 

区域2:"没有账号?注册"这几个文字定义在string里面,包含了一个<a>标签:

<string name="login_reGISter_link">没有帐号? <a href="#" mce_href="#">注册</a></string>

定义如下:


<TextView android:id="@+id/register_link" 
 android:text="@string/login_register_link" 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:layout_marginLeft="15dp" 
 android:textColor="#888" 
 android:textColorLink="#FF0066CC" 
/> 

TextView是支持简单的html标签的,如<a>标签,但并不是支持所有标签,支持更复杂的html标签得用WEBView组件。

android:textColorLink是设置文字链接的颜色. 虽然TextView支持<a>标签,但是这里是不能点此链接的,不要被假象迷惑。

区域3是一直猫的卡通图片,貌似有点丑,将就下吧:

XML/HTML代码


<ImageView android:id="@+id/miniTwitter_loGo" 
  android:src="@drawable/cat" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" 
  android:layout_alignParentRight="true" 
  android:layout_alignParentBottom="true" 
  android:layout_marginRight="25dp" 
  android:layout_marginLeft="10dp" 
  android:layout_marginBottom="25dp" 
/> 

android:layout_alignParentRight="true" 位于layout的最右边

android:layout_alignParentBottom="true" 位于layout的最底部

android:layout_marginRight="25dp" 该imageView的边框距离layout边框有25dp,其他的margin类似。

区域4 是一个带文字的图片的ImageView:


<ImageView android:src="@drawable/logo" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" 
  android:layout_toLeftOf="@id/miniTwitter_logo" 
  android:layout_alignBottom="@id/miniTwitter_logo" 
  android:paddingBottom="8dp" 
/> 
  android:layout_toLeftOf="@id/miniTwitter_logo" 在那个小猫ImageView的左边(水平位置)
  android:layout_alignBottom="@id/miniTwitter_logo" 这里意思是这两个ImageView(区域3和区域4)下边缘对齐
  android:paddingBottom="8dp" 图片距离ImageView底部边框8dp,也就是将图片上抬个8dp

实现miniTwitter登陆界面的具体步骤

具体步骤如下:

第一步:一些字符串定义

/miniTwitterLoginDemo/res/values/strings.xml


<?xml version="1.0" encoding="utf-8"?> 
<resources> 
 <string name="hello">Hello World, LoginActivity!</string> 
 <string name="login_label_username">帐号</string> 
 <string name="login_label_password">密码</string> 
 <string name="login_label_signin">登 录</string> 
 <string name="login_status_logging_in">登录中...</string> 
 <string name="login_username_hint">Email或手机号</string> 
 <string name="login_register_link">没有帐号? <a href="#" mce_href="#">注册</a></string> 
 <string name="app_name">miniTwitter</string> 
</resources> 

第二步:

/miniTwitterLoginDemo/res/values/style.xml


<?xml version="1.0" encoding="utf-8"?> 
<resources> 
  <style name="normalText" parent="@android:style/TextAppearance">      
  <item name="android:textColor">#444</item> 
  <item name="android:textSize">14sp</item> 
  </style> 
</resources> 

第三步:背景色为渐变色

/miniTwitterLoginDemo/res/drawable-mdpi/background_login.xml


<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
  <gradient 
   android:startColor="#FFACDAE5" 
   android:endColor="#FF72CAE1" 
   android:angle="45" 
  /> 
</shape>

第四步:背景色味淡蓝色且为圆角

/miniTwitterLoginDemo/res/drawable-mdpi/background_login_div_bg.xml


<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
  <solid android:color="#55FFFFFF" /> 
  <!-- 设置圆角 
  注意:  bottomRightRadius是左下角而不是右下角 bottomLeftRadius右下角--> 
  <corners android:topLeftRadius="10dp" android:topRightRadius="10dp" 
    android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp"/> 
</shape> 

第五步:

/miniTwitterLoginDemo/res/layout/login.xml


<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
 xmlns:android="http://schemas.android.com/apk/res/android" 
 android:orientation="vertical" 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 android:background="@drawable/background_login"> 
 <!-- padding 内边距 layout_margin 外边距 
     android:layout_alignParentTop 布局的位置是否处于顶部 --> 
 <RelativeLayout 
   android:id="@+id/login_div" 
   android:layout_width="fill_parent" 
   android:layout_height="wrap_content" 
   android:padding="15dip" 
   android:layout_margin="15dip" 
   android:background="@drawable/background_login_div_bg" 
   > 
   <!-- 账号 --> 
   <TextView 
     android:id="@+id/login_user_input" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_marginTop="5dp" 
     android:text="@string/login_label_username" 
     style="@style/normalText"/> 
   <EditText 
     android:id="@+id/username_edit" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:hint="@string/login_username_hint" 
     android:layout_below="@id/login_user_input" 
     android:singleLine="true" 
     android:inputType="text"/> 
 <!-- 密码 text --> 
 <TextView 
   android:id="@+id/login_password_input" 
   android:layout_width="wrap_content" 
   android:layout_height="wrap_content" 
   android:layout_below="@id/username_edit" 
   android:layout_marginTop="3dp" 
   android:text="@string/login_label_password" 
   style="@style/normalText"/> 
 <EditText 
   android:id="@+id/password_edit" 
   android:layout_width="fill_parent" 
   android:layout_height="wrap_content" 
   android:layout_below="@id/login_password_input" 
   android:password="true" 
   android:singleLine="true" 
   android:inputType="textPassword" 
 /> 
 <!-- 登录button --> 
 <Button 
   android:id="@+id/signin_button" 
   android:layout_width="wrap_content" 
   android:layout_height="wrap_content" 
   android:layout_below="@id/password_edit" 
   android:layout_alignRight="@id/password_edit" 
   android:text="@string/login_label_signin" 
   android:background="@drawable/blue_button" 
 /> 
 </RelativeLayout> 
 <RelativeLayout 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  > 
   <TextView android:id="@+id/register_link" 
    android:text="@string/login_register_link" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="15dp" 
    android:textColor="#888" 
    android:textColorLink="#FF0066CC" 
   /> 
   <ImageView android:id="@+id/miniTwitter_logo" 
    android:src="@drawable/cat" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentBottom="true" 
    android:layout_marginRight="25dp" 
    android:layout_marginLeft="10dp" 
    android:layout_marginBottom="25dp" 
     /> 
   <ImageView android:src="@drawable/logo" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toLeftOf="@id/miniTwitter_logo" 
    android:layout_alignBottom="@id/miniTwitter_logo" 
    android:paddingBottom="8dp" 
    /> 
   </RelativeLayout> 
</LinearLayout> 

第七步:

/miniTwitterLoginDemo/src/com/mytwitter/acitivity/LoginActivity.java

这里要注意的是,该Activity是无标题的,设置无标题需要在setContentView之前设置,否则会报错。


package com.mytwitter.acitivity; 
import android.app.Activity; 
import android.os.Bundle; 
import android.view.Window; 
public class LoginActivity extends Activity { 
 @Override 
 public void onCreate(Bundle savedInstanceState) { 
  super.onCreate(savedInstanceState); 
  requestWindowFeature(Window.FEATURE_NO_TITLE); 
  setContentView(R.layout.login); 
 } 
} 

到此,Android中的miniTwitter登录界面的制作就介绍完毕了,是不是做出不错的登录界面并不算难呢?谢谢大家

的阅读。

您可能感兴趣的文章:Android SharedPreferences实现记住密码和自动登录界面Android实现闪屏及注册和登录界面之间的切换效果Android登录界面的实现代码分享功能强大的登录界面Android实现代码Android QQ登录界面绘制代码Android实现QQ登录界面遇到问题及解决方法Android开发实例之登录界面的实现Android属性动画实现炫酷的登录界面Android设计登录界面、找回密码、注册功能Android实现简洁的APP登录界面


--结束END--

本文标题: Android miniTwitter登录界面开发实例

本文链接: https://www.lsjlt.com/news/25149.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Android Studio——实现登录界面
    Android Studio——实现登录界面 在移动应用开发中,登录界面是一种常见的设计需求。通过使用Android Studio,我们可以轻松实现一个简单且美观的登录界面。本文将介绍如何使用Andr...
    99+
    2023-09-25
    android studio android ide Android
  • PHP登录界面实例
    登录 来源地址:https://blog.csdn.net/m0_58464499/article/details/129665250...
    99+
    2023-09-03
    php
  • Android studio实现app登录界面
    本文实例为大家分享了Android studio设计app登录界面,供大家参考,具体内容如下 UI界面设计 在设计登录界面时,可以使用不同布局方式来实现该功能,通常情况下使用的是Li...
    99+
    2024-04-02
  • Android Studio实现登录界面功能
    本文实例为大家分享了Android Studio实现登录界面的具体代码,供大家参考,具体内容如下 题目 设计一个登录界面。要求: a) 包含用户名、密码、记住密码、“忘记...
    99+
    2024-04-02
  • Android实现登录注册界面框架
    小项目框架 今天用QQ的时候想到了,不如用android studio 做一个类似于这样的登录软件。当然QQ的实现的功能特别复杂,UI界面也很多,不是单纯的一时新奇就可以做出来的。就...
    99+
    2024-04-02
  • Android studio怎么实现app登录界面
    这篇文章主要介绍了Android studio怎么实现app登录界面的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Android studio怎么实现app登录界面文章都会有所收获,下面我们...
    99+
    2023-06-30
  • 小程序登录界面怎么开发
    这篇“小程序登录界面怎么开发”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“小程序登录界面怎么开发”文章吧。  小程序登录界面...
    99+
    2023-06-26
  • Android Studio怎么实现登录界面功能
    本文小编为大家详细介绍“Android Studio怎么实现登录界面功能”,内容详细,步骤清晰,细节处理妥当,希望这篇“Android Studio怎么实现登录界面功能”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入...
    99+
    2023-06-30
  • Android Studio如何实现简易登录界面
    这篇文章主要介绍“Android Studio如何实现简易登录界面”,在日常操作中,相信很多人在Android Studio如何实现简易登录界面问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答...
    99+
    2023-06-30
  • Android实现登录界面的注册功能
    本文实例为大家分享了Android登录界面的注册实现代码,供大家参考,具体内容如下 注册一个登录界面在控制台将输入的信息文本选框展示出来 xml界面设计(前面已发) <xml ...
    99+
    2024-04-02
  • jsp实现登录界面
    本文实例为大家分享了jsp实现登录界面的具体代码,供大家参考,具体内容如下 一.用户登录案例需求: 1.编写login.jsp登录页面 username & pas...
    99+
    2024-04-02
  • vue实现登录界面
    使用Vue实现简单的用户登录界面,登录成功以后查询账号用户类型进行相应的页面路由跳转,效果如下图所示: HTML部分: <div class="loginbody"> ...
    99+
    2024-04-02
  • Android如何实现登录界面的注册功能
    今天小编给大家分享一下Android如何实现登录界面的注册功能的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。注册一个登录界面...
    99+
    2023-06-30
  • 怎么用android做一个登录界面
    要使用Android创建一个登录界面,你需要以下步骤:1. 创建一个新的Android项目。在Android Studio中,选择“...
    99+
    2023-09-14
    android
  • 微信小程序实现登录界面示例
    本文实例为大家分享了微信小程序实现登录界面的具体代码,供大家参考,具体内容如下 注:这里使用的是原生微信小程序 使用wxss和wxml index.wxml文件中代码 <vie...
    99+
    2024-04-02
  • SwiftUI登录界面布局实现示例详解
    目录引言页面分析-元素构成实战编程-背景图片实战编程-说明文字实战编程-登录方式实战编程-辅助文字本章小结引言 为了更好地了解和学习SwiftUI,我们快速学习SwiftUI的三种基...
    99+
    2024-04-02
  • Android 实现用户登陆界面
    EditText & 简单登录界面制作 基本认识 Button是TextView的一个子类,EditView同样也是TextView的子类 其中,EditView是一个可输入内容的组件 参考属...
    99+
    2023-09-28
    android java 开发语言
  • Android实现EventBus登录界面与传值(粘性事件)
    本文实例为大家分享了Android实现EventBus登录界面与传值的具体代码,供大家参考,具体内容如下展示效果添加EventBus导入依赖compile 'org.greenrobot:eventbus:3.0.0'...
    99+
    2023-05-30
    android eventbus 登录
  • Vue实现简单登录界面
    本文实例为大家分享了Vue实现简单登录界面的具体代码,供大家参考,具体内容如下 实现: 界面实现表单规则校验结合后台 api 校验提示消息 App.vue <template&...
    99+
    2024-04-02
  • vue如何实现登录界面
    本文小编为大家详细介绍“vue如何实现登录界面”,内容详细,步骤清晰,细节处理妥当,希望这篇“vue如何实现登录界面”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。效果如下图所示:HTML部分:<div&nb...
    99+
    2023-07-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作