(Touch Android) 新浪微博Android客戶端開發第二篇:OAuth頁面的實現

在上一講【(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"
  		/>
  
  
  
  <RelativeLayout
	android: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>


 

 

 到此,我們這個頁面就做出來了

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章