广告
返回顶部
首页 > 资讯 > 移动开发 >Android仿新浪微博启动界面或登陆界面(1)
  • 424
分享到

Android仿新浪微博启动界面或登陆界面(1)

新浪微博登陆界面启动新浪Android 2022-06-06 05:06:48 424人浏览 独家记忆
摘要

本文为大家分享了Android模仿新浪微博启动界面&登陆界面的具体实现代码,供大家参考,具体内容如下 启动界面 主要有两个功能: 1.加载启动动画 2.判断网络,有

本文为大家分享了Android模仿新浪微博启动界面&登陆界面的具体实现代码,供大家参考,具体内容如下

启动界面

主要有两个功能:

1.加载启动动画
2.判断网络,有者直接进入登陆界面,否则去设置网络

代码较简单,主要采用AlphaAnimation()方法和动画监听器,使一张图片产生渐变动画。在动画启动的时候判断网络,动画结束时完成判断并进入登陆界面。



public class SplashActivity extends Activity {
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.splash);
 ImageView splashimage = (ImageView) findViewById(R.id.splashimage);
 //透明度渐变动画
 AlphaAnimation animation = new AlphaAnimation(0.1f, 1.0f);
 //设置动画时长
 animation.setDuration(3000);
 //将组件和动画进行关联
 splashimage.setAnimation(animation);
 animation.setAnimationListener(new Animation.AnimationListener() {
  //动画启动执行
  @Override
  public void onAnimationStart(Animation animation) {
  Toast.makeText(SplashActivity.this, "欢迎使用DeMon制作微博", Toast.LENGTH_LONG).show();
  //检查并网络的方法
  Tools.checkNetWork(SplashActivity.this);
  }
  //动画结束执行
  @Override
  public void onAnimationEnd(Animation animation) {
  Intent intent = new Intent(SplashActivity.this, LoginActivity.class);
  startActivity(intent);
  finish();
  }
  //动画重复执行
  @Override
  public void onAnimationRepeat(Animation animation) {
  }
 });
 }

使用ConnectivityManager获取系统的连接服务,然后获取代表联网状态的NetWorkInfo对象,获取网络的连接情况,如果没有网络则生成一个AlertDialog引导进行网络设置。该方法位于Tools.java中。


 
 public static void checkNetWork(final SplashActivity context) {
 if (!NetWorkStatus(context)) {
  TextView msg = new TextView(context);
  msg.setText("请设置网络!");
  AlertDialog.Builder b = new AlertDialog.Builder(context).
   setIcon(R.drawable.notnet)
   .setTitle("没有可用的网络")
   .setMessage("是否对网络进行设置?");
  b.setPositiveButton("是", new DialogInterface.OnClickListener() {
  public void onClick(DialogInterface dialog, int whichButton) {
   //跳转到设置网络界面
   context.startActivity(new Intent(Settings.ACTION_SETTINGS));
  }
  }).setNeutralButton("否", new DialogInterface.OnClickListener() {
  public void onClick(DialogInterface dialog, int whichButton) {
   dialog.cancel();
   context.finish();
  }
  }).create().show();
 }
 }
 
 public static boolean NetWorkStatus(Context context) {
 //获取系统的连接服务
 ConnectivityManager connect = (ConnectivityManager) context.getSystemService(Context
  .CONNECTIVITY_SERVICE);
 if (connect == null) {
  return false;
 } else {
  // 获取代表联网状态的NetWorkInfo对象,获取网络的连接情况
  NetworkInfo[] infos = connect.getAllNetworkInfo();
  if (infos != null) {
  for (NetworkInfo network : infos) {
   if (network.getState() == NetworkInfo.State.CONNECTED) {
   return true;
   }
  }
  }
 }
 return false;
 }

SplashActivity的布局文件splash.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">
 <ImageView
 android:id="@+id/splashimage"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:scaleType="fitXY"
 android:src="@drawable/splashimage"/>
 <ProgressBar
 style="@android:style/Widget.ProgressBar.Inverse"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentBottom="true"
 android:layout_alignParentStart="true"
 android:layout_gravity="center"
 android:layout_marginBottom="64dp"
 android:layout_marginStart="130dp">
 </ProgressBar>
</RelativeLayout>

 

登陆界面

此界面只有几个按钮,故合在一条博客里。

微博按钮触发进入到到授权界面


public class LoginActivity extends Activity {
 private Button sinalogin;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.login);
 sinalogin = (Button) findViewById(R.id.sinalogin);
 sinalogin.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {
  Intent intent = new Intent(LoginActivity.this, OAuthActivity.class);
  startActivity(intent);
  LoginActivity.this.finish();
  }
 });
 }
}


布局文件login.xml两个自定义样式的EditText,一个普通按钮(此处纯粹摆设)。只有微博登陆按钮有用。


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@drawable/background"
  android:gravity="center_vertical"
  android:orientation="vertical"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin">
 <EditText
 android:id="@+id/username"
 android:layout_width="match_parent"
 android:layout_height="40dip"
 android:background="@drawable/bg_edittext"
 android:ems="10"
 android:inputType="textPersonName">
 </EditText>
 <EditText
 android:id="@+id/passworld"
 android:layout_width="match_parent"
 android:layout_height="40dip"
 android:layout_marginTop="20dip"
 android:background="@drawable/bg_edittext"
 android:ems="10"
 android:inputType="textPassWord"/>
 <LinearLayout
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:orientation="horizontal">
 <Button
  android:id="@+id/login"
  android:layout_width="200dp"
  android:layout_height="wrap_content"
  android:layout_marginTop="20dip"
  android:layout_weight="1"
  android:text="登录"/>
 <Button
  android:id="@+id/sinalogin"
  android:layout_width="200dp"
  android:layout_height="38dp"
  android:layout_marginTop="20dip"
  android:layout_weight="1"
  android:background="@drawable/weibologin"/>
 </LinearLayout>
</LinearLayout>

您可能感兴趣的文章:Android笔记之:App应用之启动界面SplashActivity的使用详解Android中App的启动界面Splash的编写方法Android开发基础之创建启动界面Splash Screen的方法Android 个人理财工具一:项目概述与启动界面的实现Android编程实现启动界面的方法分析Android 应用启动欢迎界面广告的实现实例Android UI设计与开发之实现应用程序只启动一次引导界面Android 避免APP启动闪黑屏的解决办法(Theme和Style)Android启动画面的实现方法Android开发中简单设置启动界面的方法


--结束END--

本文标题: Android仿新浪微博启动界面或登陆界面(1)

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

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

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

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

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作