编程语言
首页 > 编程语言> > android – Facebook应用程序类型没有互联网连接消息

android – Facebook应用程序类型没有互联网连接消息

作者:互联网

如何在标签视图下方显示的Facebook应用中不显示互联网连接消息.

解决方法:

您可以在XML文件中进行设计,然后将其可见性设置为不可见,如下所示:

<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>

在您的代码中使用广播接收器,如下所示:

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);               
        }
    }       
};

标签:android,android-wifi,android-dialog,android-facebook
来源: https://codeday.me/bug/20190831/1777824.html