发布于 2017-10-11 13:27:47 | 116 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

Android移动端操作系统

Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。


这篇文章主要为大家详细介绍了Android仿新浪微博启动界面或登陆界面的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

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

启动界面

主要有两个功能:

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

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


/**
 * Created by D&LL on 2016/5/25.
 * 初始页面加载界面
 */
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中。


 /**
 * 设置网络
 *
 * @param context
 */
 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>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持PHPERZ。



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务