Android开发问题汇总
<div id="cnblogs_post_body" style="margin-bottom: 20px; word-break: break-word; font-family: tahoma, arial, sans-serif; font-size: 12px; line-height: 18px; "><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">注:Android 5.0的问题总结在<a href="http://www.cnblogs.com/bjzhanghao/p/4194164.html" target="_blank" style="color: rgb(0, 90, 148); text-decoration: none; ">这个帖子</a>里。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">1、用(SDK starter package)的installler安装Android SDK时提示无法找到JDK,但实际上机器上已经安装了JDK。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">一个对不少人有效的解决方法是看到此提示时先点一下“回退”按钮,再点“下一步”,就会发现JDK被找到了。<a href="http://stackoverflow.com/questions/4382178/android-sdk-installation-doesnt-find-jdk" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接</a> </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">但在我机器上这个方法不起作用。所以我选择不使用installer,而是下载zip格式的文件,解压缩后运行SDK Manager.exe即可。<a href="http://stackoverflow.com/questions/1919340/android-sdk-setup-under-windows-7-pro-64-bit" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接</a></p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">2、在Eclipse里新建一个Android项目,运行/调试时提示“Could not find xxx.apk!”</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">网上提到的大部分解决方案是clean整个项目,或选fix project properties菜单项。但对我的环境不起作用。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">升级到Eclipse 3.7后,新创建的android项目在Build阶段报告一个异常“sun/security/x509/X500Name”,怀疑与所用的jdk(IBM JDK6)有关。果然,卸载IBM JDK并安装SUN JDK后问题解决。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">3、让程序适应不同的屏幕分辨率</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">可参考这个链接:<a href="http://ucdchina.com/snap/7166" style="color: rgb(0, 90, 148); text-decoration: none; ">Android屏幕分辨率问题</a>。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">4、在android模拟器里用10.0.2.2可访问宿主机。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">5、在setWidth()方法里指定的宽度是以pixel为单位的,如何转换为使用dip(device independent pixels)为单位?</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">使用下面的代码,<a href="http://stackoverflow.com/questions/2406449/does-setwidthint-pixels-use-dip-or-px" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接</a> </p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: 'Courier New' !important; line-height: 1.5 !important; "><div style="line-height: 1.5 !important; "> <span style="line-height: 1.5 !important; color: rgb(0, 128, 0); ">//</span><span style="line-height: 1.5 !important; color: rgb(0, 128, 0); "> Converts 14 dip into its equivalent px</span></div><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; "><span style="font-size: 12px !important; line-height: 1.5 !important; ">Resources r </span><span style="font-size: 12px !important; line-height: 1.5 !important; ">=</span><span style="font-size: 12px !important; line-height: 1.5 !important; "> getResources();<br></span><span style="font-size: 12px !important; line-height: 1.5 !important; color: rgb(0, 0, 255); ">float</span><span style="font-size: 12px !important; line-height: 1.5 !important; "> px </span><span style="font-size: 12px !important; line-height: 1.5 !important; ">=</span><span style="font-size: 12px !important; line-height: 1.5 !important; "> TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, </span><span style="font-size: 12px !important; line-height: 1.5 !important; ">14</span><span style="font-size: 12px !important; line-height: 1.5 !important; ">, r.getDisplayMetrics());</span></p></div><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">6、弹出式对话框的用法,<a href="http://www.cnblogs.com/hummersofdie/archive/2011/03/22/1991104.html" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>介绍得比较详细。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">7、导出apk文件时需要签名,<a href="http://archive.cnblogs.com/a/2109381/" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>比较详细。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">8、android界面设计原则,参考<a href="http://blog.3gstdy.com/archives/278" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">9、使用merge(而不是layout)可以达到在避免重复写layout的同时减少layout的数量。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">10、真机USB调试比用AVD调试快得多,设置也很简单,见<a href="http://www.zjsyc.com/blog/article/google/Milestone_USB_Android.html" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>。不过10.0.2.2不能用了,真机可以通过wifi访问局域网内的服务器。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">11、android-ui-utils,一个不错的在线Android图标生成器,<a href="http://android-ui-utils.googlecode.com/hg/asset-studio/dist/index.html" style="color: rgb(0, 90, 148); text-decoration: none; ">地址在此</a>。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">12、调试时如果出现莫名其妙的空指针错误,例如findViewByID()返回null,先试试clean一下整个project,通常都能解决。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">13、让ListView里无数据时显示一行信息。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; "><a href="http://stackoverflow.com/questions/6634651/how-to-toggle-android-listview-empty-text" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接</a>,注意ListView和TextView的id。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">14、用自己的图标替换ListView里的RadioButton</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">在用作row的layout里添加一个图片,在java code里覆盖adapter的getView()方法,根据ListView的getCheckedItemPosition()结果设置图片的可见性。注意不要通过setOnClickListener()方法设置view里的图片可见性,因为ListView只维护可见的那些row控件,这样做会导致很奇怪的结果(点第一条记录结果第二条记录被选中,并且滚动ListView时选中状态还会随机变化,<a href="http://stackoverflow.com/questions/3984146/android-custom-listview-onitemclicklistener-weird-issues" style="color: rgb(0, 90, 148); text-decoration: none; ">见此链接</a>)。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">另外一个办法是通过style设置checkMark为所需要的图标,可能是更简单的解决方案(还没试)。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">Update: 以上结果基于对ListView实现不了解的情况,其实使用RadioButton是可以实现的,见#22。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">15、ListView的selection和choice是完全不同的,所以不要指望ListView#clearChoice()能清楚你已经是checked状态的那些item。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">16、屏幕方向变化时(横屏->竖屏,或反过来),ListView里发生变化的内容丢失,状态回到开始时的样子。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">当屏幕方向发生变化时,android会重建整个Activity以便你构造更适合某个方向的UI。为了避免这种情况,在AndroidManifest.xml里的那个Activity声明上增加android:configChanges="orientation" 即可。详见<a href="http://stackoverflow.com/questions/2590162/android-listview-in-activity-getting-refreshed-on-changing-orientation" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接</a>。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">17、各手机平台仿真器/模拟器的<a href="http://www.mobilexweb.com/emulators" style="color: rgb(0, 90, 148); text-decoration: none; ">下载链接</a>。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">18、AlertDialog#show()方法是不会阻塞当前线程的。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">19、让不同Activity之间进行通信,例如一个TabActivity里有多个Activity,它们之间需要传递一些消息。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">可使用BroadcastReceiver机制。 <a href="http://stackoverflow.com/questions/5527559/accessing-sibling-tabs-in-an-android-application" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接</a>。要注意的是,tab还未启动时是无法接收到消息的,所以要在tabhost所在的activity里也接收消息,当tab启动时传给它。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">20、Android SDK里的style和theme文档</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; "><a href="http://developer.android.com/guide/topics/ui/themes.html" style="color: rgb(0, 90, 148); text-decoration: none; ">见此链接</a>。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">21、Tab的样式。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">Android的tab样式问题比较多,不同版本的样式也不一样。这里有一个自定义样式的<a href="http://blog.csdn.net/ComteDeLaFere/article/details/5647935" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接</a>。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">22、在ListView里使用单选/复选按钮。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">问题很多,<a href="http://stackoverflow.com/questions/4842349/android-listview-with-radiobutton-checkbox-in-singlechoice-mode-and-a-custom-row" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>看起来解决了问题,但在我的环境里没试验成功。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">Update: 以复选按钮为例,本质的问题在于ListView里的复选按钮不知道对应的model是哪个,需要事先用CheckBox#setTag(myModelObject)关联,onclick事件里用getTag()改变其选中状态。建议看<a href="http://commonsware.com/Android/excerpt.pdf" style="color: rgb(0, 90, 148); text-decoration: none; ">这篇文档</a>。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">23、strings.xml里定义的字符串里增加参数。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">在字符串里用“%1$s”、“%2$d”表示参数的序号和类型,然后用String.format()方法赋值。参考<a href="http://stackoverflow.com/questions/3656371/dynamic-string-using-string-xml" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">24、嵌入条码/二维码扫描功能</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">使用zxing。方法是在手机上先安装BarcodeScanner.apk,然后在程序里调用其提供的Activity,该Activity会返回扫描结果。 <a href="http://www.ispiders.net/?p=192" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接</a></p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">25、改变ListView里每个Row的背景颜色</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">直接在getView()里写view.setBackgroundColor()是不行的。正确的方法是先在drawable目录里建一个xml文件,自己起名如my_row.xml,内容如下(关键是第一个和第四个<item>):</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: 'Courier New' !important; line-height: 1.5 !important; "><pre style="white-space: pre-wrap; font-family: 'Courier New' !important; "><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); "><?</span><span style="line-height: 1.5 !important; color: rgb(255, 0, 255); ">xml version="1.0" encoding="utf-8"</span><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">?></span><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); "><</span><span style="line-height: 1.5 !important; color: rgb(128, 0, 0); ">selector </span><span style="line-height: 1.5 !important; color: rgb(255, 0, 0); ">xmlns:android</span><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">="http://schemas.android.com/apk/res/android"</span><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">></span>
<span style="line-height: 1.5 !important; color: rgb(0, 0, 255); "><</span><span style="line-height: 1.5 !important; color: rgb(128, 0, 0); ">item </span><span style="line-height: 1.5 !important; color: rgb(255, 0, 0); ">android:state_window_focused</span><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">="false"</span><span style="line-height: 1.5 !important; color: rgb(255, 0, 0); "> android:state_selected</span><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">="true"</span><span style="line-height: 1.5 !important; color: rgb(255, 0, 0); ">
android:drawable</span><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">="@android:color/transparent"</span> <span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">/></span>
<span style="line-height: 1.5 !important; color: rgb(0, 0, 255); "><</span><span style="line-height: 1.5 !important; color: rgb(128, 0, 0); ">item </span><span style="line-height: 1.5 !important; color: rgb(255, 0, 0); ">android:state_selected</span><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">="true"</span><span style="line-height: 1.5 !important; color: rgb(255, 0, 0); "> android:drawable</span><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">="@android:color/transparent"</span> <span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">/></span>
<span style="line-height: 1.5 !important; color: rgb(0, 0, 255); "><</span><span style="line-height: 1.5 !important; color: rgb(128, 0, 0); ">item </span><span style="line-height: 1.5 !important; color: rgb(255, 0, 0); ">android:state_pressed</span><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">="true"</span><span style="line-height: 1.5 !important; color: rgb(255, 0, 0); "> android:state_selected</span><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">="false"</span><span style="line-height: 1.5 !important; color: rgb(255, 0, 0); ">
android:drawable</span><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">="@android:color/transparent"</span> <span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">/></span>
<span style="line-height: 1.5 !important; color: rgb(0, 0, 255); "><</span><span style="line-height: 1.5 !important; color: rgb(128, 0, 0); ">item </span><span style="line-height: 1.5 !important; color: rgb(255, 0, 0); ">android:state_selected</span><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">="false"</span><span style="line-height: 1.5 !important; color: rgb(255, 0, 0); "> android:drawable</span><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">="@color/solid_red"</span> <span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">/></span>
<span style="line-height: 1.5 !important; color: rgb(0, 0, 255); "></</span><span style="line-height: 1.5 !important; color: rgb(128, 0, 0); ">selector</span><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">></span> </pre></div><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">然后在getView()里这样写就可以了:</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: 'Courier New' !important; line-height: 1.5 !important; "><pre style="white-space: pre-wrap; font-family: 'Courier New' !important; "> <span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">if</span><span style="line-height: 1.5 !important; "> (item.getStopId().equals(User.stopId)) {
view.setBackgroundResource(R.drawable.my_row);
} </span><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">else</span><span style="line-height: 1.5 !important; "> {
view.setBackgroundResource(android.R.drawable.list_selector_background);
}</span></pre></div><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; "><a href="http://daniel-codes.blogspot.com/2010/07/how-to-change-listview-rows-background.html" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接1</a> <a href="http://stackoverflow.com/questions/2562051/listview-item-background-via-custom-selector" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接2</a> <a href="http://stackoverflow.com/questions/2217753/changing-background-color-of-listview-items-on-android" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接3</a></p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">26、在一个TableLayout里让Button宽度相同并占满表格宽度(想象一个由按钮组成的九宫格)</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">如果Button上的文字不长,按一般的方法就可以实现,例如<a href="http://en.androidwiki.com/wiki/Dynamically_adding_rows_to_TableLayout" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>。当Button上的文字很长,还是会使布局变乱,每个列的长度将不一样。解决方案是将按钮的layout_width设为0,layout_height设置为所需要的值,需要换行时将singleLine设置为false,最后将按钮的gravity设置为center。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">27、对切换屏幕方向的处理 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">参考stackoverflow上的<a href="http://stackoverflow.com/questions/456211/activity-restart-on-rotation-android" style="color: rgb(0, 90, 148); text-decoration: none; ">一个典型讨论</a>。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">当MyActivity位于一个TabActivity里时,我做了一些实验表明, TabActivity是否声明android:configChanges="keyboardHidden|orientation"与MyActivity无关,只有MyActivity做了上述声明后才会在改变方向时触发onConfigurationChanged()方法。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">28、strings.xml里的字符串包含html格式标签时</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">需要用<Data><!]></Data>把html代码包起来。<a href="http://stackoverflow.com/questions/4637780/android-string-xml-reading-html-tags-problem" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接</a> </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">29、在AlertDialog里用ListAdapter(如ArrayAdapter)时,文字不显示。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">view的resourceId要用select_dialog_singlechoice而不能用simple_list_item_single_choice,否则文字颜色会与背景颜色相同而无法显示。<a href="http://stackoverflow.com/questions/2336427/alertdialog-doesnt-display-items-from-listadapter-hide-options" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接</a></p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">30、在android程序里使用第三方包的配置方法 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">参考<a href="http://stackoverflow.com/questions/3642928/adding-a-library-jar-to-an-eclipse-android-project" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>成功。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">31、定制tabhost的外观</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">这方面的需求和问题网上都很多,主要的解决方案有基于tabhost的和基于radiobutton的两大类,这里有几个可以参考的链接。<a href="http://joshclemm.com/blog/?p=136" style="color: rgb(0, 90, 148); text-decoration: none; ">链接1</a>,<a href="http://bakhtiyor.com/2009/10/iphonish-tabs/" style="color: rgb(0, 90, 148); text-decoration: none; ">链接2</a>,<a href="http://www.mokriya.com/blog/2011/02/13/custom-tabs-in-android/" style="color: rgb(0, 90, 148); text-decoration: none; ">链接3</a> </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">32、取得当前屏幕方向</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">有好几个方法可以得到orientation值,但一些得到的值不对,例如getWindowManager().getDefaultDisplay().getOrientation()和getReqestedOrientation()。我实验下来比较靠谱的是getResources().getConfiguration().orientation。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">33、Activity里第一个View是EditText的时候,软键盘自动弹出。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">似乎只是一些机型会这样做。要阻止软键盘弹出,可在onCreate()里加一行代码。<a href="http://stackoverflow.com/questions/2496901/android-on-screen-keyboard-auto-popping-up" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接</a> </p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: 'Courier New' !important; line-height: 1.5 !important; "><pre style="white-space: pre-wrap; font-family: 'Courier New' !important; "> <span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">this</span>.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);</pre></div><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">34、Dialog的theme问题</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">使用Theme.Light主题时,Dialog显示不正常。相关讨论:<a href="http://code.google.com/p/android/issues/detail?id=922" style="color: rgb(0, 90, 148); text-decoration: none; ">链接1</a>,<a href="http://stackoverflow.com/questions/2422562/how-to-change-theme-for-alertdialog" style="color: rgb(0, 90, 148); text-decoration: none; ">链接2</a></p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">35、注意区分CheckBox和RadioButton的OnClickListener和OnCheckedChangeListner</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">使用前者时,当在代码里执行myCheckBox.setChecked(true),不会触发事件,而后者会触发事件。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">36、监视GPS开启/关闭事件 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">用GpsStatus.Listener不可靠(事件不上来),这个链接的方法是监视Settings里的事件:<a href="http://stackoverflow.com/questions/5026549/how-can-i-monitor-the-status-of-the-gps-adapter-using-android-sdk" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接</a></p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">37、仿真器横屏</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">快捷键ctrl+f11。有人提到ctrl+f12和numpad 7也可以,但我这里不起作用。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">38、用JAXB生成KML对应的Java Code时会遇到一些问题,解决方法如下:</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">1)写一个binding文件如bindings.xjb放在与ogckml22.xsd同一目录,内容可参考<a href="http://stackoverflow.com/questions/7437891/solve-jaxb-name-collision-in-the-objectfactory-class-problem-with-customisatio" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>(根据错误提示要删除几行)</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">2)在命令行里加-extension</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">3)在命令行里加-target 2.1(否则生成的java类的annotation带有jdk6不识别的关键字"required")</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">完整的命令行如下:</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: 'Courier New' !important; line-height: 1.5 !important; "><pre style="white-space: pre-wrap; font-family: 'Courier New' !important; ">xjc -xmlschema -verbose -extension -b bindings.xjb -d src -target 2.1 ogckml22.xsd </pre></div><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">39、ListPreference的entryValues只能使用string-array</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">如果使用了integer-array,在点击这个preference项时会产生一个空指针异常,相关讨论见<a href="http://stackoverflow.com/questions/5227478/getting-integer-or-index-values-from-a-list-preference" style="color: rgb(0, 90, 148); text-decoration: none; ">链接1</a>、<a href="http://code.google.com/p/android/issues/detail?id=2096#makechanges" style="color: rgb(0, 90, 148); text-decoration: none; ">链接2</a>。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">Update: 又发现一个ListPreference的新问题,即使用string-array,defaultValue值也不能取太大的(超过Integer.MAX_VALUE)整数,否则defaultValue不起作用(选项没有缺省被选中)。 真是问题多多。android版本2.2。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">40、Android提供了方便的Share机制,但一般都是把文字share到微博或SMS,如何能"share"文字到SD卡文件呢? </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; "><a href="http://stackoverflow.com/questions/7975742/android-show-save-to-sd-in-intent-chooser-intent-action-send" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>描述了同样的问题,等待有人回答。 目前的想法是,在程序里自己实现一个接受ACTION_SEND的activity,做法可参考<a href="http://stackoverflow.com/questions/5077244/how-can-i-add-my-android-app-to-share-dialog" style="color: rgb(0, 90, 148); text-decoration: none; ">此链接</a>、或<a href="http://eggie5.com/8-hook-share-picture-via-menu-android" style="color: rgb(0, 90, 148); text-decoration: none; ">此文章</a>。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">41、一个在线查看kml文件的网站,供参考。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; "><a href="http://www.gpsvisualizer.com/" style="color: rgb(0, 90, 148); text-decoration: none; ">GPS Visualizer</a> </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">42、关于onSaveInstanceState()的使用</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">通常与onCreate()配合,而非onRestoreInstanceState(),参考<a href="http://stackoverflow.com/questions/4096169/onsaveinstancestate-and-onrestoreinstancestate" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">2015/5/18补充:一个误区是onSaveInstanceState()方法是当activity被系统销毁时才调用,其实是当activity“变得容易被系统销毁”时就会被调用,例如当按下home键时,此时activity不再在前台显示,也就变得容易被销毁了。<a href="http://www.cnblogs.com/heiguy/archive/2010/10/30/1865239.html" target="_blank" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接</a>,<a href="http://blog.csdn.net/liuhanhan512/article/details/8674369" target="_blank" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接2</a></p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">43、ListView里点击一个item背景色不变为橘黄(缺省的反馈颜色),各种OnClick事件不被触发。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">一种可能是在item的布局文件(如foo_list_row.xml)里使用了下面的这些属性(自动滚动显示文字时常会用到),去掉后即可恢复正常:</p><div style="line-height: 1.5 !important; "><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: 'Courier New' !important; line-height: 1.5 !important; "><pre style="white-space: pre-wrap; font-family: 'Courier New' !important; ">android:ellipsize="marquee" android:scrollHorizontally="true"<span style="line-height: 1.5 !important; ">
android:marqueeRepeatLimit</span>="marquee_forever" android:focusable="true"<span style="line-height: 1.5 !important; ">
android:focusableInTouchMode</span>="true" </pre></div></div><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">44、实现不停向上滚动的ListView</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">假设你有一个长长的list需要自动展示,方式是每隔几秒向上滚动一行,有点类似TextView的marquee功能(跑马灯?)。这个需求可以通过Handler实现,具体参考<a href="http://groups.google.com/group/android-developers/browse_thread/thread/e0aaecf2c462a1f6" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>;当列表滚动到最后一行时,直接滚回第一行显得很生硬,可以用<a href="http://stackoverflow.com/questions/2332847/how-to-create-a-closed-circular-listview" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>里提供的方法解决。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">45、在Button的文字旁加图片</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">在<Button>里使用android:drawableLeft="@drawable/my_icon" android:gravity="left|center_vertical"即可,类似的可以加在右侧或上下方。但如果Button有其他状态时,需要用selector指定不同状态下的图片。此外,图片的大小是不会自动根据Button调整的。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">46、旧版本兼容</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">参考sdk文档里的<a href="http://developer.android.com/resources/articles/backward-compatibility.html" style="color: rgb(0, 90, 148); text-decoration: none; ">这个文章</a>。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">47、轻松实现圆角背景</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">不需要做圆角图片,看看<a href="http://stackoverflow.com/questions/1683185/android-listview-with-rounded-corners" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>,很方便,注意把angle改为45的倍数否则运行时报错。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">48、Android内存泄漏检测</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">在DDMS可以查看heap使用情况,大概了解是否有内存泄漏。DDMS还可以dump出.hprof文件,后者可以用<a href="http://eclipse.org/mat/" style="color: rgb(0, 90, 148); text-decoration: none; ">Eclipse MAT</a>打开,进一步分析错误原因。注意,startActivity()后要根据情况决定是否调用finish()方法(如果需要back则不finish(),在适当的时机用FLAG_ACTIVITY_CLEAR_TOP一并回收内存空间),未finish()的activity是会一直占用内存的。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">49、Android的第三方library </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; "><a href="http://stackoverflow.com/questions/4078479/what-android-3rd-party-libraries-are-there" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>总结了不少。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">50、Android UI设计模式</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">参考<a href="http://www.androidpatterns.com/" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">51、Google Map扩展的使用。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">参考<a href="http://mobiforge.com/developing/story/using-google-maps-android" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">52、当Spinner是invisible状态时,貌似调用mySpinner.setSelection(i) 不会触发其onItemSelected()事件。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">53、实现gzip压缩服务器返回的json对象时,注意要response.setContentType("application/json"),并且在server.xml里把application/json设置到compressableMimeType里才能实现。我因为前一个原因浪费了三四个小时。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">54、对AlertDialog.Builder应用定制的theme</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">使用ContextThemeWrapper,用法参<a href="http://stackoverflow.com/questions/2422562/how-to-change-theme-for-alertdialog" style="color: rgb(0, 90, 148); text-decoration: none; ">考这个链接</a>。但后来发现这个方法不起作用,有一种说法是这个方法只对部分android版本有效,也有说其根本无效的(都是在so上)。用AlertDialog.Builder的setVIew()方法也是有问题的,因为你会发现在这个view的旁边一圈(假设你的view是浅色背景)还是黑色的,效果很不好。其实如果只是要将对话框设置为白色背景,可以使用AlertDialog.Builder的setInverseBackgroundForced(true)方法,很简单,很直接。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">55、从gallery选择图片的一些可用参数 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">参考<a href="http://www.androidworks.com/crop_large_photos_with_android" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>,和这个<a href="http://code.google.com/p/android/issues/detail?id=1480" style="color: rgb(0, 90, 148); text-decoration: none; ">相关issue</a> (文件得不到原始图片,只能得到缩小后的图片)。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">56、从gallery取图片时要注意内存是有限的,而图片可能很大。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">利用inSampleSize可以帮助解决,参考<a href="http://stackoverflow.com/questions/477572/android-strange-out-of-memory-issue/823966#823966" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>的代码。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">57、当程序进程被系统kill掉(常常在内存紧张时发生):</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">HttpClient的session可以用persist方式保留;</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">其余数据建议保留在SharedPreferenes里; </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">onActivityResult()里是能够获得另一个activity传回来的intent里的参数的;</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">58、连接到真机时提示Unable to open sync connection! </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">原因未知,解决方法是在真机的设置里去掉usb调试,然后重新勾选。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">59、得到GPS状态(寻星或已获得位置)</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">这个问题看似简单,但Android里的LocationListener#onStatusChanged()方法工作不正常,表现为在大多数版本下都不会被调用。<a href="http://stackoverflow.com/questions/2021176/how-can-i-check-the-current-status-of-the-gps-receiver" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>里提供的方法试了一下好像是可以用的。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">60、在Android里画统计图(柱图饼图等等)</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; "><a href="http://stackoverflow.com/questions/424752/any-good-graphing-packages-for-android" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>里给出了不少解决方案,我暂时选择的是aChartEngine,用法和JFreechart比较类似,参数超多,目前的活跃度也不错。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">61、进程经常被kill</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">可以考虑启动一个service(即使什么都不做),这样进程的“重要性”就变得很高,因此就不容易被kill了。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">62、“Receiver not registered”错误</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">执行unregisterReceiver(myReceiver)方法时,如果之前没有注册过myReceiver,会抛出这个异常。<a href="http://stackoverflow.com/questions/6165070/receiver-not-registered-exception-error" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接</a></p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">63、应用在后台运行,需要弹出对话框(例如触发自service产生的事件)时报错:“BadTokenException: Unable to add window”</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">利用isFinishing()测试activity是否在后台,<a href="http://vinnysoft.blogspot.com/2010/11/androidviewwindowmanagerbadtokenexcepti.html" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接</a> </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">64、Emulator太慢了?</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">试试Android x86,据说比官方的快很多(我还没试过,正在下载)。 <a href="http://stackoverflow.com/questions/1554099/slow-android-emulator" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接</a></p><div style="line-height: 1.5 !important; ">65、禁止自动切换到横屏模式</div><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: 'Courier New' !important; line-height: 1.5 !important; "><pre style="white-space: pre-wrap; font-family: 'Courier New' !important; "><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); "><</span><span style="line-height: 1.5 !important; color: rgb(128, 0, 0); ">activity </span><span style="line-height: 1.5 !important; color: rgb(255, 0, 0); ">android:name</span><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">=".SomeActivity"</span><span style="line-height: 1.5 !important; color: rgb(255, 0, 0); "> android:label</span><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">="@string/app_name"</span><span style="line-height: 1.5 !important; color: rgb(255, 0, 0); "> android:screenOrientation</span><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">="portrait"</span><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">></span>...<span style="line-height: 1.5 !important; color: rgb(0, 0, 255); "></</span><span style="line-height: 1.5 !important; color: rgb(128, 0, 0); ">acivity</span><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">></span> </pre></div><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; "><a href="http://stackoverflow.com/questions/582185/android-disable-landscape-mode" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接</a> </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">66、几个众包模式的beta测试平台</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">iOS最著名的是testflight,也有其他一些类似的测试平台支持android,详见<a href="http://www.quora.com/Is-there-a-Testflight-equivalent-for-Android" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">67、实现锁机后黑屏但不出现锁机画面</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: 'Courier New' !important; line-height: 1.5 !important; "><pre style="white-space: pre-wrap; font-family: 'Courier New' !important; ">getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);</pre></div><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">还有一个功能类似的flag是FLAG_DISMISS_KEYGUARD,区别在于前者只对当前activity有效,后者全局有效。另外前者对安全锁屏也有效,后者则只对普通锁屏有效。附一个<a href="http://stackoverflow.com/questions/6335875/help-with-proximity-screen-off-wake-lock-in-android" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接</a>。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">但是前者有一个问题,就是在两个都设置了FLAG_SHOW_WHEN_LOCKED的activity间切换时,可能锁屏界面会闪一下。见此<a href="http://code.google.com/p/android/issues/detail?id=18908" style="color: rgb(0, 90, 148); text-decoration: none; ">问题报告</a>。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">68、一些可用于android应用性能测试和内存泄漏检测的工具</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">见<a href="http://hi.baidu.com/donghaozheng/blog/item/72943b2a187ef3355343c191.html" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">69、进度条的一个bug</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">重设setMax()以后显示的进度百分比不正确,至少在Android 2.1 (API Level 7)里有这个问题。 见<a href="http://stackoverflow.com/questions/4348032/android-progressbar-does-not-update-progress-view-drawable" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>和<a href="http://code.google.com/p/android/issues/detail?id=12945" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">70、当ListView的item里包含控件(如按钮、复选框)时 ,这个item无法被选中。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">Android不允许选中ListView里带有focusable元素的item,解决方法是将该控件的focusable属性设置为false。<a href="http://stackoverflow.com/questions/1121192/android-custom-listview-unable-to-click-on-items" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接</a></p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">71、帮助做简单web测试的工具(构造并发送各种http请求)</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; "><a href="http://stackoverflow.com/questions/1087185/http-testing-tool-easily-send-post-get-put" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>里总结了不少。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">72、Tab放在底部(仿iphone风格)</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">中文的教程看了好几个都不靠谱,so上的<a href="http://stackoverflow.com/questions/2395661/android-tabs-at-the-bottom" style="color: rgb(0, 90, 148); text-decoration: none; ">一个链接</a>搞定,或者这个<a href="http://www.androidcookers.co.cc/2011/12/i-phone-style-tabbar-in-android.html" style="color: rgb(0, 90, 148); text-decoration: none; ">带有源码的教程</a>。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">73、让ListView没有数据时也显示HeaderView/FooterView</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">技巧是让empty view包含headerview/footerview,见<a href="http://stackoverflow.com/questions/7449522/list-activity-with-header-footer-and-empty-all-visible" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">74、在Google map上添加popup的方法</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">最简单的方法见<a href="http://stackoverflow.com/questions/3707923/show-popup-above-map-marker-in-mapview/3829582#3829582" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">75、一个网站,可以搜索android相关项目的代码和资源。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; "><a href="http://androidxref.com/source/" style="color: rgb(0, 90, 148); text-decoration: none; ">链接在此</a> </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">76、Android里的Search Activity不支持返回结果到调用其的Activity(因为onSearchRequested()方法没有调用startActivityForResult()启动search activity)</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">SO上有若干个提出此问题的帖子,例如<a href="http://stackoverflow.com/questions/4211677/get-result-from-searchmanager-activity-to-main-activity-in-android" style="color: rgb(0, 90, 148); text-decoration: none; ">链接1</a>、<a href="http://stackoverflow.com/questions/3597919/how-to-handle-callback-from-search-manager/5968730" style="color: rgb(0, 90, 148); text-decoration: none; ">链接2</a>等等,没有特别方便的办法解决,一个我没试过但看回复应该可行的方法见<a href="http://blog.dpdearing.com/2011/05/getting-android-to-call-onactivityresult-after-onsearchrequested/" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">77、查看apk文件内容的工具</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">推荐<a href="http://www.google.com.hk/url?sa=t&rct=j&q=apktool&source=web&cd=1&ved=0CHMQFjAA&url=http%3A%2F%2Fcode.google.com%2Fp%2Fandroid-apktool%2F&ei=EKioT_fZIumfmQW80tThBA&usg=AFQjCNH6zK6mfduq08j1-bcnOf1Rz8k9fA" style="color: rgb(0, 90, 148); text-decoration: none; ">apktool</a>,一个命令行工具,用法如下:</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: 'Courier New' !important; line-height: 1.5 !important; "><pre style="white-space: pre-wrap; font-family: 'Courier New' !important; ">>apktool.bat d my.apk</pre></div><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">可以还原所有的资源文件,但.java文件一般无法还原。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">78、Android中使用的各类图标的标准尺寸</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">请参考sdk自带的<a href="http://developer.android.com/guide/practices/ui_guidelines/icon_design.html" style="color: rgb(0, 90, 148); text-decoration: none; ">guideline文档</a>。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">79、Android的Searchable接口,无法让调用者获得查询结果。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">参考这篇文档可以实现,思路是自己用startActivityResult() 启动搜索界面,然后再onActivityResult()里取出结果。我测试可行,但该文档有两处错误需要注意:</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">1) 是handleIntent()而非handleActivity()</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">2) 在startActivityResult()前最好intent.setAction(Intent.ACTION_SEARCH) 一下。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">另外,注意按该文章中提到的<a href="http://developer.android.com/guide/topics/search/search-dialog.html#LifeCycle" style="color: rgb(0, 90, 148); text-decoration: none; ">官方文档</a>实现相应的newIntent()和onCreate()方法,以及在AndroidManifest.xml里设置调用者的android:launchMode="singleTop"。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">80、很诡异的问题,有时EditText无法输入文字(软键盘正常弹出但字符进不去文本框),必须切换到另一个输入法才可以输入。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">经测试,有些机型存在这个问题,具体原因还不详。以下链接可能与此有关:<a href="http://wchinaw.iteye.com/blog/1142226" style="color: rgb(0, 90, 148); text-decoration: none; ">链接1</a> </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">81、定时重复执行一段程序</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">要执行类似闹钟这样的功能,用AlarmManager配合BroadCastReceiver即可,网上有很多例子不再赘述。值得一提的是,在这个BroadCastReceiver里不要执行异步操作(例如异步访问一个远程服务、获取当前位置等等),因为onReceive()方法一旦执行结束,用于容纳BroadCastReceiver的进程随时可能被系统kill掉,导致异步操作结束后出现异常。解决的办法是在onReceive()方法里启动一个Service(我用的是startService,用bindService的方式可能也行),在Service里执行任何操作就可以了。参考<a href="http://developer.android.com/reference/android/content/BroadcastReceiver.html#ReceiverLifecycle" style="color: rgb(0, 90, 148); text-decoration: none; ">BroadCastReceiver Life Cycle</a></p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">82、Monkey测试</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: 'Courier New' !important; line-height: 1.5 !important; "><pre style="white-space: pre-wrap; font-family: 'Courier New' !important; ">>adb shell monkey -v -p com.my.app 100 </pre></div><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">MonkeyRunner可以进行更高级的测试。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">83、用getIntent().getExtras().clear()无法清除掉extras里的数据</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">原因是getExtras()返回的是一个copy实例,用getIntent().removeExtra()可一个个清除。<a href="http://stackoverflow.com/questions/4520961/removing-extras-from-passed-in-intent" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接</a> </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">84、用AlertDialog实现输入对话框时,若直接builder.setView(myEditText)文本框显得太长。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">用dialog.setView()可以指定padding(注意是dialog.setView()而不是builder.setView()),具体见<a href="http://stackoverflow.com/questions/4927208/android-edittext-in-alertdialog-seems-too-wide" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">85、在TextView里显示图片</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">通过Html.fromHtml()方法可以在TextView里显示HTML格式的文本,但只支持部分tag:</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: 'Courier New' !important; line-height: 1.5 !important; "><pre style="white-space: pre-wrap; font-family: 'Courier New' !important; ">myTextVIew.setText(Html.fromHtml(myHtmlStr))</pre></div><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">要在TextView里显示远程图片,必须向fromHtml()函数里提供一个ImageGetter对象,在它的getDrawable()方法里获取远程图像并转换为Drawable类型。示例代码请参考<a href="http://stackoverflow.com/questions/3077809/images-in-textview" style="color: rgb(0, 90, 148); text-decoration: none; ">此链接</a>。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">如果TextView设置了android:lineSpacingMultiplier属性,将导致图片显示的位置不正确(顶部多出一些空白),用android:lineSpacingExtra属性则没有这个问题。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">如果图片加载比较慢将导致整个TextView空白很长时间,为解决这个问题需要异步加载图片,这样文字可以先出来,待图片下载完毕后再补充道文字中间。实现方法是扩展Drawable,具体方法参考这两个链接:<a href="http://stackoverflow.com/questions/7424512/android-html-imagegetter-as-asynctask" style="color: rgb(0, 90, 148); text-decoration: none; ">链接1</a>、<a href="http://stackoverflow.com/questions/7870312/android-imagegetter-images-overlapping-text" style="color: rgb(0, 90, 148); text-decoration: none; ">链接2</a> ,其中链接1的方案存在图片尺寸不正确的问题,原因是TextView#invalidate()没能起作用(原因不详),用链接2提供的方法可以解决,<a href="http://stackoverflow.com/questions/7739649/async-imagegetter-not-functioning-properly" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>提到用textView.setText(textView.getText())也可以工作但我没试。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">86、在TextView里显示列表(<li>标签) </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">Android的TextView只支持一小部分的html标签(见<a href="http://stackoverflow.com/questions/11214001/show-ul-li-in-android-textview" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>),缺省是不支持<ol>、<ul>和<li>这样的列表标签的。通过TagHandler可以实现一个简单的列表效果(见<a href="http://stackoverflow.com/questions/3150400/html-list-tag-not-working-in-android-textview-what-can-i-do" style="color: rgb(0, 90, 148); text-decoration: none; ">此链接</a>),但这个方法有个严重问题:当列表文字超过一行时,第二行的文字是顶头的没有缩进效果(见<a href="http://stackoverflow.com/questions/3715776/indent-bullet-list-in-textview" style="color: rgb(0, 90, 148); text-decoration: none; ">这个提问</a>),而该问题暂时还没有好的解决方法。 </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">87、百度地图android sdk问题</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">百度地图最大的问题:文档太烂!百度地图sdk版本比较多,网上充斥着各种版本的例子代码,官网上的例子代码也不清晰,在线文档含混不清。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">遇到过一个奇怪的问题,与<a href="http://www.eoeandroid.com/thread-325896-1-1.html" style="color: rgb(0, 90, 148); text-decoration: none; ">这个帖子</a>描述的情况相同,即第二次打开地图只能显示上次缓存过区域的地图,最后删除了所有onPause()、onResume()和onDestroy()里的百度地图相关方法才解决。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">88、启用Andoird设备的otg功能</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">在/system/etc/permissions目录里检查是否有名为android.hardware.usb.host.xml的文件,如果没有,新建一个内容如下:</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: 'Courier New' !important; line-height: 1.5 !important; "><pre style="white-space: pre-wrap; font-family: 'Courier New' !important; "><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); "><</span><span style="line-height: 1.5 !important; color: rgb(128, 0, 0); ">permissions</span><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">></span>
<span style="line-height: 1.5 !important; color: rgb(0, 0, 255); "><</span><span style="line-height: 1.5 !important; color: rgb(128, 0, 0); ">feature </span><span style="line-height: 1.5 !important; color: rgb(255, 0, 0); ">name</span><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">="android.hardware.usb.host"</span> <span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">/></span>
<span style="line-height: 1.5 !important; color: rgb(0, 0, 255); "></</span><span style="line-height: 1.5 !important; color: rgb(128, 0, 0); ">permissions</span><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">></span></pre></div><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">89、命令行对一个未签名apk进行签名</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; "> jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore my_application.apk alias_name </p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; "><a href="http://developer.android.com/tools/publishing/app-signing.html" style="color: rgb(0, 90, 148); text-decoration: none; ">参考连接</a></p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">90、Pull-to-refresh控件不显示内容问题</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">将ListView替换为PullToRefreshListView,setAdapter()后发现列表中没有数据显示,调试发现adapter里是有数据的,而listView的getView()方法没有被执行到。最后发现原因是在布局文件的<com.handmark.pulltorefresh.library.PullToRefreshListView>元素中指定了android:visibility="gone"属性(在.java文件里在setAdapter()之前先调用了listView.setVisibility(View.VISIBLE)),在布局文件里去掉此属性,改为在activity的onCreate()里执行listView.setVisibility(View.GONE)后恢复正常,没有深入调查这两种方式对PullToRefreshListView有什么区别,对标准ListView是没有区别的。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">91、切换fragment时fragment显示不全</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">在fragmentTransaction.replace(R.id.layoutRoot, newTransaction)时,发现当layoutRoot是LinearLayout时,(有时)newTransaction的高度无法充满layoutRoot(虽然已经指定了高度为match_parent,指定高度为固定值也无效),后来将layoutRoot改为FrameLayout问题解决。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; "><a href="http://stackoverflow.com/questions/17129312/android-pulltorefresh-listview-always-empty" style="color: rgb(0, 90, 148); text-decoration: none; ">提供了一些线索的参考链接</a></p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">92、利用Activity的android:process属性</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">在开发一个视频播放器过程中,遇到一个问题,当视频还在缓冲时按返回键退出当前activity,应用失去反应长达数秒。后来在AndroidManifest.xml里对这个activity增加了android:process=":player"后问题解决,因为这个属性使得此activity在一个独立的进程运行,当activity被关闭时,此进程也被杀掉。这样,即使播放器有未完成的工作,也不会影响到主程序的UI线程了。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">需要注意,用PreferenceManager.getDefaultSharedPreferences()得到的SharedPreferences实例,是不支持跨进程访问的,因此在独立的进程里将无法向这样获得的SharedPreferences实例存取数据。解决的办法是改为使用context.getSharedPreferences(prefName, Context.MODE_MULTI_PROCESS)获取SharedPrefences实例。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">不过还是要特别注意,在多进程环境下,如果你用一个<strong>静态变量</strong>缓存了SharedPreference里的内容,由于静态变量在多个进程间不是共享的(Application对象也不是跨进程共享的),所以取出的结果可能不是你想要的。解决办法 1)去掉这个作为缓存的静态变量,每次都直接从SharedPreferences里取 2) 有人建议使用<a href="https://developer.android.com/reference/android/os/MemoryFile.html" style="color: rgb(0, 90, 148); text-decoration: none; ">MemoryFile</a>作为跨进程的机制,但我没有实际测试过,而且用起来应该会比Application对象繁琐。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; "><a href="https://www.vitamio.org/docs/Tutorial/2014/0423/32.html" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接</a> <a href="http://stackoverflow.com/questions/19705818/multi-process-shared-preferences-return-wrong-value-in-multi-process-environment" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接2</a> <a href="http://stackoverflow.com/questions/8639101/can-i-have-a-multi-process-global-variable" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接3</a></p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">93、Service的START_STICKY与START_NOT_STICKY的区别</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">参考<a href="http://stackoverflow.com/questions/9093271/start-sticky-and-start-not-sticky" style="color: rgb(0, 90, 148); text-decoration: none; ">这个链接</a>:当系统由于资源不足可能会杀掉一个service,之后如果系统又有了足够资源,若被杀掉的service是START_STICKY的,则系统会调用其onStartCommand()方法恢复这个service;若被杀掉的service是START_NOT_STICKY的,则系统不会尝试恢复这个service。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">94、如何用纯java的方式获取apk文件版本信息?</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">apk文件就是zip文件,解析并读取AndroidManifest.xml里的信息即可。开源项目<a href="https://github.com/joakime/android-apk-parser" target="_blank" style="color: rgb(0, 90, 148); text-decoration: none; ">android-apk-parser</a>已经实现了这个功能,可以直接在java项目里使用。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">95、Android手机使用https代替http会带来明显的性能问题吗?</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">对CPU消耗来讲,不会。见<a href="http://stackoverflow.com/questions/4606168/do-mobile-devices-have-enough-cpu-to-support-https-for-all-of-a-websites-traffi" target="_blank" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接</a></p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">对网络消耗来讲,有一些影响。见<a href="http://www.semicomplete.com/blog/geekery/ssl-latency.html" target="_blank" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接</a></p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">关于在手机端“接受所有证书”做法的安全性,见<a href="http://stackoverflow.com/questions/2642777/trusting-all-certificates-using-httpclient-over-https" target="_blank" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接</a>。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">注意:ssl处于tcp和http之间,使用https后,url也是加密过的,因此不需要担心api地址暴露(浏览器历史除外)。<a href="http://stackoverflow.com/questions/499591/are-https-urls-encrypted" target="_blank" style="color: rgb(0, 90, 148); text-decoration: none; ">参考链接</a></p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">96、代码混淆</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">将project.properties里的#proguard.config=xxx这句前面的#去掉即可。会按照android sdk目录里的proguard-android.txt设置文件进行混淆,如果项目有特殊要求,在项目目录下的proguard-project.txt里进行设置。有两点注意:</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">1) 只有在正式export apk时才会进行混淆,直接运行产生的bin/xxx.apk不会进行混淆;</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">2) library工程里的混淆设置不起作用,以宿主工程的设置为准。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">97、Fragment里getActivity()有时为null</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">一般当activity所在进程在后台被系统回收,然后用户重新回到这个进程时,activity重建后发生。解决方法是在activity的onSaveInstanceState()方法里保存fragment的状态:</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: 'Courier New' !important; line-height: 1.5 !important; "><pre style="white-space: pre-wrap; font-family: 'Courier New' !important; "><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">public</span> <span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">void</span><span style="line-height: 1.5 !important; "> onSaveInstanceState(Bundle outState) {
activity.getSupportFragmentManager().putFragment(outState, </span>"current_fragment"<span style="line-height: 1.5 !important; ">, currentFragment);
}</span></pre></div><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; "> 然后在activity的onCreate()方法里恢复:</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: 'Courier New' !important; line-height: 1.5 !important; "><pre style="white-space: pre-wrap; font-family: 'Courier New' !important; "><span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">if</span> (savedInstanceState != <span style="line-height: 1.5 !important; color: rgb(0, 0, 255); ">null</span><span style="line-height: 1.5 !important; ">) {
currentFragment </span>= (Fragment) activityBase.getSupportFragmentManager().getFragment(savedInstanceState, "current_fragment"<span style="line-height: 1.5 !important; ">);
}</span></pre></div><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">这样currentFragment所代表的fragment实例的getActivity()就不为null了。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">98、分级Preference界面布局的实现方式</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">引用<a href="http://blog.csdn.net/ixiaobu/article/details/8609935" target="_blank" style="color: rgb(0, 90, 148); text-decoration: none; ">这篇文章</a>的总结:Android 3.0之前:采用PreferenceScreen嵌套的方法;Android 3.0及之后:采用Preference Headers的方法。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">采用Preference Headers方法时,要求继承PreferenceActivity,但这样就无法同时继承ActionbarActivity了(<a href="http://stackoverflow.com/questions/7928874/actionbar-in-preferenceactivity" target="_blank" style="color: rgb(0, 90, 148); text-decoration: none; ">问题链接</a>)。<a href="https://github.com/AndroidDeveloperLB/ActionBarPreferenceActivity" target="_blank" style="color: rgb(0, 90, 148); text-decoration: none; ">这个</a>第三方library可以基本解决这个问题。</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">99、自定义进度条progressbar的风格</p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">这篇文章总结得很好,特记录在此:<a href="http://www.tiemenschut.com/how-to-customize-android-progress-bars/" target="_blank" style="color: rgb(0, 90, 148); text-decoration: none; ">How-to: Customize Android progress bars</a></p><p style="margin: 10px auto; font-size: 14px; line-height: 1.5 !important; ">(未完待续) </p></div><div id="MySignature" style="font-family: tahoma, arial, sans-serif; font-size: 12px; line-height: 18px; "><p style="margin-top: 15px; margin-bottom: 15px; text-indent: 2em; font-size: 14px; line-height: 20px; ">如果觉得本文内容有帮助:试试我开发的Android应用 <a href="http://www.apptimer.cn/" style="color: rgb(68, 68, 68); "><b>应用计时</b></a> 或 <a href="http://www.cnblogs.com/bjzhanghao/archive/2011/06/28/2092514.html#" style="color: rgb(68, 68, 68); "><b>推荐+1</b></a>(需登录)</p></div><p></p> 本文来自:http://www.cnblogs.com/bjzhanghao/archive/2011/06/28/2092514.html
页:
[1]