1.获取屏幕的分辨率
在 Activity 里使用如下代码,宽度和高度的单位是像素
Display display = getWindowManager().getDefaultDisplay();
int screenWidth = display.getWidth();
int screenHeight = display.getHeight();
2.绘制文本
使用 FontMetrics 类
参考
http://www.iteye.com/topic/474526
3.禁止自动横竖屏切换
在AndroidManifest.xml的Activity节点加入如下属性
android:screenOrientation="portrait"
portrait是纵向,landscape是横向
4.Resources and Assets
无论是使用Res\raw还是使用Asset存储资源文件,文件大小UNCOMPRESS限制为1MB
参考
http://wayfarer.iteye.com/blog/547174
5.SDK 1.6 新增加SD卡写入权限
在AndroidManifest.xml加入以下代码
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
SDK1.6之前的项目自适应,无需此权限也可以写入SD卡。
6.在eclipse中查看Android Framework源代码
代码下载
- SDK 1.5
http://www.box.net/shared/16au19tqlp
- SDK 1.6
http://www.box.net/shared/dh4dr9ir7j
- SDK 2.2
http://www.box.net/shared/dic2t0blj1
参考
http://www.iteye.com/topic/534010
7.给View注册ContextMenu
void
setOnCreateContextMenuListener
(View.OnCreateContextMenuListener
l)
Register a callback to be invoked when the context menu for this view is being built.
8.给Preference设置Intent
void
setIntent
(Intent
intent)
Sets an
Intent
to be used for
startActivity(Intent)
when this Preference is clicked.
9.包含CheckBox的ListView
ListView item中加入checkbox后onListItemClick 事件无法触发。
原因:checkbox的优先级高于ListItem于是屏蔽了ListItem的单击事件。
解决方案:设置checkbox的android:focusable="false"
10.取得当前的Locale
Locale locale = context.getResources().getConfiguration().locale;
11.使用android.text.format.Time类代替java.util.Calendar类
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.
12.调整WebView字体大小
WebView.getSettings().setDefaultFontSize()
WebView.getSettings().setDefaultZoom()
13.View Animation总结
参考
14.检查网络状态
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"/>
15.Parse JSON String
参考
-
http://www.androidcompetencycenter.com/2009/10/json-parsing-in-android/
-
http://wiki.fasterxml.com/JacksonInFiveMinutes
-
http://stackoverflow.com/questions/2818697/sending-and-parsing-json-in-android
16.设置EditText的输入模式
url, password, email, 电话键盘等
设置
android:inputType
属性
17.Crash Report
-
http://code.google.com/p/acra/
-
http://code.google.com/p/android-send-me-logs/
18.用户解锁消息
android.intent.action.USER_PRESENT
只能在代码里注册Receiver
19.屏幕消息
android.intent.action.SCREEN_ON
android.intent.action.SCREEN_OFF
只能在代码里注册Receiver
分享到:
相关推荐
Mobly Bundled Snippets是一组片段,通过公开适用于测试的公共Android API的简化版本,使...snippet_shell.py com.google.android.mobly.snippet.bundled >>> print(s.help()) Known methods: bluetoothDisable() ret
Android Snippets This repository holds code snippets used in Android documentation on developer.android.com. It is a work in progress, as many snippets are still embedded as static HTML. Quality ...
android-widget-snippet 一些有用的Android小部件和代码片段
This is a classic game of dominoes where you play against a computer player for the Android platform. Domino pieces and game state is working OK, but there are more than a few things missing. First, ...
NiceSpinner is a re-implementation of the default Android's spinner, with a nice arrow animation and a different way to display its content. It follows the material design guidelines, and it is ...
一个Intellij&Android Studio插件,可将实时模板添加到您的IDE中,从而节省了在Flutter中编写样板的时间。 可用片段 通用的 捷径 展开式 描述 Flutter Docs animatedBldr 动画制作器 创建一个动画生成器。 子...
Android This Repository contains snippets of little features I have worked on while I was learning and building Android apps....Snippet Descriptions Messages Does the simple task of importing a user's te
Android-片段android 开发者的一些片段
Tomo is a collection of fast image processing effects for Android. Its main goal is to generate dynamic content for aesthetically pleasing apps. The motivation behind this project can be read in this ...
Android手机短信/彩信管理-包括了已接收短信修改, 进入初始页面 EntryPage,传递数据: 1 标题,即该viewtitem的名称 2 类型,短信为0,彩信为1,所有会话为2, 点击短信时 传递标题“短信”,传递0,进入...
Android代码模板或代码片段
:octopus: Supporting Code [ Repo / Code Snippet ] link :video_camera: Video / Include Video 内容 火力基地 Firebase云消息传递 Firebase远程配置 Firebase性能监控 蓝牙 谷歌地图 测验 Kotlin 开发工具 出版 ...
Code snippet below dumps TCP Socket instances found in heap HeapImage hi = HeapUnit.captureHeap(); for(HeapInstance i: hi.instances(SocketImpl.class)) { // fd field in SocketImpl class is nullified ...
crawler4j crawler4j is an open source web crawler for Java ...To use the latest release of crawler4j, please use the following snippet in your pom.xml edu.uci.ics crawler4j 4.4.0 Snapshot You can
集成过程遇到问题挺多的,需要的小伙伴们就下载看看吧,很简单的一个小项目
Snippet 推荐阅读: 整理的 —— Android 项目开发中的 MyApplication —— Android 项目图片三级缓存、异步加载类 —— Android 项目中加载图片通过 HashMap 缓存 Bitmap 软引用对象 —— Android 项目中让属性动画...
复制代码代码如下:<span xss=removed></span><pre code_snippet_id=”75788″ snippet_file_name=”blog_20131121_2_1289480″ name=”code” class=”html”><pre code_snippet_id=”75788″ snippet_file_name=...
snippet_cs integer snippet的编码方式,彩信:UTF-8为106,短信为0 read integer 是否有未读信息:0-未读,1-已读 type integer 会话类型,0-普通会话(只有一个接收者),1-广播会话(多个接收者) error integer...
:memo: NOTE - PASTE PART 2 SNIPPET HERE:在此处的顶部,粘贴此作业的NOTE - PASTE PART 2 SNIPPET HERE:的README模板。 这将显示您的开发过程的历史记录,向用户讲述您完成的故事,以及每个步骤的应用外观和功能...
In convertor, we can generate some training/inference code snippet to simplify the retrain/evaluate work. Deployment We provide some guidelines to help you deploy your models to other hardware ...