2014-10-12 60 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