Facebook的应用程序类型没有互联网连接的消息 [英] Facebook app type no internet connection message

查看:293
本文介绍了Facebook的应用程序类型没有互联网连接的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能显示没有互联网连接的消息一样,在出现下面的选项卡视图Facebook的应用程序。

How can I show no internet connection message like in facebook app that appears below the tab view.

推荐答案

您可以在XML文件中设计这个,然后设置其可见不可见这样的:

You can design this in your XML file and then set its visibility to invisible like this:

<RelativeLayout
    android:id="@+id/relativelayout_connection"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:alpha="0.8"
    android:background="@android:color/black" >

    <TextView
        android:id="@+id/textView_noInternetConnection"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_centerInParent="true"
        android:text="No Internet Connection."
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@android:color/white" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/textView_noInternetConnection"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@+id/textView_noInternetConnection"
        android:src="@drawable/warrning" />
</RelativeLayout>

在你的code使用的广播接收机是这样的:

In your code use the broadcast receiver like this:

private BroadcastReceiver mConnReceiver = new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {
        boolean noConnectivity = intent.getBooleanExtra(
                ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
        /*String reason = intent
                .getStringExtra(ConnectivityManager.EXTRA_REASON);*/
        boolean isFailover = intent.getBooleanExtra(
                ConnectivityManager.EXTRA_IS_FAILOVER, false);

        @SuppressWarnings("deprecation")
        NetworkInfo currentNetworkInfo = (NetworkInfo) intent
                .getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
        // NetworkInfo otherNetworkInfo = (NetworkInfo)
        // intent.getParcelableExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO);

        if (noConnectivity){    
            if(mRelativeLayout != null)
            mRelativeLayout.setVisibility(View.VISIBLE);

        }
        else if (currentNetworkInfo.isConnected()) {
            mRelativeLayout.setVisibility(View.GONE);


        } else if (isFailover) {
            Toast.makeText(getApplicationContext(), "Failover",
                    Toast.LENGTH_LONG).show();
        } else {
            mRelativeLayout.setVisibility(View.GONE);               
        }
    }       
};

这篇关于Facebook的应用程序类型没有互联网连接的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆