Android

By admin, 10 二月, 2015

public boolean isOnline() {
    ConnectivityManager cm =
        (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    return netInfo != null && netInfo.isConnectedOrConnecting();
}

在AndroidManifest.xml中添加下面权限:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

标签

By admin, 10 二月, 2015

AndroidManifest.xml的activity里添加android:screenOrientation="portrait"

<activity android:name=".SomeActivity" android:label="@string/app_name" android:screenOrientation="portrait">

标签

By admin, 10 二月, 2015

<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:gravity="center"
    android:text="@string/**yourtextstring**"
/>

标签

By admin, 10 二月, 2015

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;

如果不在Activity里:

WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();

标签