在 Activity 里使用如下代码,宽度和高度的单位是像素
Display display = getWindowManager().getDefaultDisplay();
int screenWidth = display.getWidth();
int screenHeight = display.getHeight();
使用 FontMetrics 类
参考
http://www.iteye.com/topic/474526
在AndroidManifest.xml的Activity节点加入如下属性
android:screenOrientation="portrait"
portrait是纵向,landscape是横向
无论是使用Res\raw还是使用Asset存储资源文件,文件大小UNCOMPRESS限制为1MB
参考
http://wayfarer.iteye.com/blog/547174
在AndroidManifest.xml加入以下代码
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
SDK1.6之前的项目自适应,无需此权限也可以写入SD卡。
代码下载
参考
http://www.iteye.com/topic/534010
void setOnCreateContextMenuListener (View.OnCreateContextMenuListener l)
Register a callback to be invoked when the context menu for this view is being built.
void setIntent (Intent intent)
Sets an Intent
to be used for startActivity(Intent)
when this Preference is clicked.
ListView item中加入checkbox后onListItemClick 事件无法触发。
原因:checkbox的优先级高于ListItem于是屏蔽了ListItem的单击事件。
解决方案:设置checkbox的android:focusable="false"
Locale locale = context.getResources().getConfiguration().locale;
The Time class is a faster replacement for the java.util.Calendar and java.util.GregorianCalendar classes. An instance of the Time class represents a moment in time, specified with second precision. It is modelled after struct tm, and in fact, uses struct tm to implement most of the functionality.
WebView.getSettings().setDefaultFontSize()
WebView.getSettings().setDefaultZoom()
参考
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo();
return (info != null && info.isConnected());
}
public static boolean isWifiConnected(Context context) {
return
getNetworkState(context, ConnectivityManager.TYPE_WIFI) == State.CONNECTED;
}
public static boolean isMobileConnected(Context context) {
return
getNetworkState(context, ConnectivityManager.TYPE_MOBILE) == State.CONNECTED;
}
private static State getNetworkState(Context context, int networkType) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getNetworkInfo(networkType);
return info == null ? null : info.getState();
}
需要加入权限
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
参考
url, password, email, 电话键盘等
设置 android:inputType 属性
android.intent.action.USER_PRESENT
只能在代码里注册Receiver
android.intent.action.SCREEN_ON
android.intent.action.SCREEN_OFF
只能在代码里注册Receiver