(Touch Android) 新浪微博Android客户端开发第二篇:OAuth页面的实现

来源:互联网 发布:宝能万科大战结局知乎 编辑:程序博客网 时间:2024/05/21 11:22

在上一讲【(Touch Android) 新浪微博Android客户端开发第一篇:Logo 页面的实现】,已经完成了Logo页面的跳转,当然Logo页面跳转到的页面是登陆页面,当在登陆的时候会有这样一种情况:就是系统还未又任何的授权用户,这时候该怎么办呢。

所以我们会在登陆页面的onCreate 方法里面判断有没有授权用户的存在,如果没有,则跳转到授权页面。

本篇呢就主要是对授权Activity页面布局文件的讲解:

效果图:

 

 

首先分析一下该页面是如何来布局的:

 

整个页面可以分成两部分:

①、背景;

②、Dialog(弹出框)

 

难点在Dialog上面,这个Dialog是透明的,并且浮在背景上面,透明的Dialog该怎么做呢?我们一步一步来实现

 

首先是布局文件:auth.xml

  

<?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/main_bg"></LinearLayout>


 这个文件相当的简单,‘android:background="@drawable/main_bg">’ 这句便是加入了背景。

 

 

Dialog 布局文件:authorize_dialog.xml

<?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:orientation="vertical"  android:padding="15dip">        <LinearLayout  android:layout_width="wrap_content"  android:layout_height="wrap_content">    <ImageView   android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:src="@drawable/info"/>    <TextView   android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:text="@string/authTip"  android:layout_marginLeft="5dip"  android:textSize="20dip"  android:textColor="@color/black"  />    </LinearLayout>    <TextView   android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:text="@string/authTipMsg"  android:layout_marginLeft="5dip"  android:layout_marginRight="5dip"  android:textSize="18dip"  android:layout_marginTop="10dip"  />        <RelativeLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:gravity="center"android:layout_alignParentBottom="true">       <Button android:id="@+id/btn_auth_begin"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:background="@drawable/auth_begin_d"    android:layout_marginTop="10dip"    android:textColor="@color/white"    android:layout_gravity="center"   />    </RelativeLayout>  </LinearLayout>


 

 

布局文件我们都有,接下来我们看看Activity是如何来写的

AuthActivity:

public class AuthActivity extends Activity{private Dialog dialog;protected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);this.setContentView(R.layout.auth);//加载Dialog布局文件View digView = View.inflate(this, R.layout.authorize_dialog, null);//实例化一个Dialog对象,并且用R.style.auth_dialog作为样式dialog = new  Dialog(this, R.style.auth_dialog);dialog.setContentView(digView);//dialog使用digView作为布局文件dialog.show();}}


我们主要一下这句代码“dialog = new Dialog(this, R.style.auth_dialog);” 这里需要一个样式文件,那下面看看这个样式又是如何

 

<resources><style name="auth_dialog" parent="@android:style/Theme.Dialog"><item name="android:windowFrame">@null</item><!--Dialog的windowFrame框为无 --><item name="android:windowIsFloating">true</item><!--是否浮现在activity之上 --><item name="android:windowIsTranslucent">false</item> <!-- 是否半透明 --><item name="android:windowNoTitle">true</item><item name="android:windowBackground">@drawable/dialog_bg</item><item name="android:backgroundDimEnabled">false</item></style></resources>


 

 

 到此,我们这个页面就做出来了