2014-10-12 63 views
0

我有一個聊天app.If連接丟失,我想阻止screen.Example:當連接丟失塊屏幕

如果一切正常,以及用戶看到這樣的畫面:

enter image description here

當連接丟失,用戶會看到如下屏幕:

enter image description here

當連接丟失用戶的sh不能寫信息或不能點擊發送按鈕。這是我的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" 
    android:background="#ECECFB" 
    android:orientation="vertical" > 

    <RelativeLayout 
     android:id="@+id/comment_layout" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:background="@drawable/border_top" 
     android:layout_marginTop="5dp" 
     > 

     <EditText 
      android:id="@+id/message" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_toLeftOf="@+id/get_from_user" 
      android:textSize="14sp" > 

      <requestFocus /> 
     </EditText> 

    <ImageButton 
     android:id="@+id/get_from_user" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:gravity="right" 
     android:background="@drawable/send_button_bg" /> 

    </RelativeLayout> 

    <ListView 
     android:id="@+id/message_list" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_above="@+id/comment_layout" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:stackFromBottom="true" 
android:transcriptMode="normal" > 
    </ListView> 

</RelativeLayout> 

我該怎麼做?我需要的XML

回答

0

使用一個BroadcastReceiver,並在的onReceive檢查使用

ConnectionManager connMgr=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); 
     activeInfo = connMgr.getActiveNetworkInfo(); 
     if (activeInfo != null && activeInfo.isConnected()) 
{ 
//load a different xml 
} 

註冊採取適當的行動接收器,還可以使用

使用許可權的android的連接方法:NAME =「機器人。 permission.ACCESS_NETWORK_STATE「

+0

否我需要xml.I知道如何顯示此屏幕 – 2014-10-12 13:48:25

+0

http://stackoverflow.com/questions/2176922/how-to-create-transparent-activity-in-android – therealprashant 2014-10-12 14:04:32

+0

如果我着火一個新的活動,我的聊天ap p將停止。我不能這樣做,我必須進行同樣的活動。 – 2014-10-12 14:08:32