﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-The NoteBook of EricKong-随笔分类-Android</title><link>http://www.blogjava.net/jjshcc/category/50951.html</link><description>桑巴葡语翻译工作室是广州市最专业葡萄牙语翻译机构-www.puyufanyi.com-欢迎寻找Java,As400,Mainframe的猎头eric_cc#qq.ccom(把#换成@)</description><language>zh-cn</language><lastBuildDate>Wed, 04 Mar 2015 09:18:06 GMT</lastBuildDate><pubDate>Wed, 04 Mar 2015 09:18:06 GMT</pubDate><ttl>60</ttl><item><title>解决android:background背景图片被拉伸问题</title><link>http://www.blogjava.net/jjshcc/archive/2015/03/01/423105.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Sat, 28 Feb 2015 16:31:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2015/03/01/423105.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/423105.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2015/03/01/423105.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/423105.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/423105.html</trackback:ping><description><![CDATA[<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px;">ImageView中XML属性src和background的区别：</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px;"><span style="color: #000099;">background会根据ImageView组件给定的长宽进行拉伸，而src就存放的是原图的大小，不会进行拉伸</span>。src是图片内容（前景），bg是背景，可以同时使用。</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px;">此外：<strong>scaleType只对src起作用；bg可设置透明度，比如在ImageButton中就可以用android:scaleType控制图片的缩放方式</strong></p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px;"><br />
</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px;">如上所述，background设置的图片会跟View组件给定的长宽比例进行拉伸。举个例子， 36x36 px的图标放在 xhdpi 文件夹中，在854x480（FWVGA，对应hdpi）环境下，按照</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px;">xhdpi : hdpi : mdpi: ldip =&nbsp;2 : 1.5 : 1 : 0.75</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px;">的比例计算，在FWVGA下，图标的实际大小应该是 27x27。</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px;">但是当我把它放到一个 layout_width = 96px, layout_height = 75px 的 LinearLayout，布局代码如下：</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px;"></p>
<div bg_html"="" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 927.015625px; overflow: auto; padding-top: 1px; line-height: 26px; margin: 18px 0px !important;">
<div style="padding-left: 45px;">
<div style="padding: 3px 8px 10px 10px; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: #f8f8f8; border-left-color: #6ce26c;"><strong>[html]</strong>&nbsp;<a href="http://blog.csdn.net/oathevil/article/details/23707359#" title="view plain" style="color: #a0a0a0; text-decoration: none; background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); background-color: inherit; border: none; padding: 1px; margin: 0px 10px 0px 0px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/oathevil/article/details/23707359#" title="copy" style="color: #a0a0a0; text-decoration: none; background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); background-color: inherit; border: none; padding: 1px; margin: 0px 10px 0px 0px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><a href="https://code.csdn.net/snippets/292476" target="_blank" title="在CODE上查看代码片" style="color: #a0a0a0; text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 1px; margin: 0px 10px 0px 0px; display: inline-block; width: 16px; height: 16px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;"><img src="https://code.csdn.net/assets/CODE_ico.png" width="12" height="12" alt="在CODE上查看代码片" style="border-style: none; max-width: 100%; position: relative; top: 1px; left: 2px;" /></a><a href="https://code.csdn.net/snippets/292476/fork" target="_blank" title="派生到我的代码片" style="color: #a0a0a0; text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 1px; margin: 0px 10px 0px 0px; display: inline-block; width: 16px; height: 16px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;"><img src="https://code.csdn.net/assets/ico_fork.svg" width="12" height="12" alt="派生到我的代码片" style="border-style: none; max-width: 100%; position: relative; top: 2px; left: 2px;" /></a>
<div style="position: absolute; left: 379px; top: 700px; width: 18px; height: 18px; z-index: 99;"><embed id="ZeroClipboardMovie_1" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="18" height="18" name="ZeroClipboardMovie_1" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=1&amp;width=18&amp;height=18" wmode="transparent"></div>
</div>
</div>
<ol start="1" style="padding: 0px; border: none; list-style-position: initial; list-style-image: initial; background-color: #ffffff; color: #5c5c5c; margin: 0px 0px 1px 45px !important;">
    <li style="border-style: none none none solid; border-left-width: 3px; border-left-color: #6ce26c; list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">&lt;</span><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">LinearLayout</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">android:gravity</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"center"</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">android:layout_width</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"96px"</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">android:layout_height</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"75px"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">&gt;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
    <li style="border-style: none none none solid; border-left-width: 3px; border-left-color: #6ce26c; list-style: decimal-leading-zero outside; background-color: #f8f8f8; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">&lt;</span><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">ImageButton</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">android:layout_width</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"wrap_content"</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">android:layout_height</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"wrap_content"</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">android:background</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"@drawable/toolbar_bg"</span><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">/&gt;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li>
    <li style="border-style: none none none solid; border-left-width: 3px; border-left-color: #6ce26c; list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">&lt;/</span><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">LinearLayout</span><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">&gt;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
</ol>
</div>
<br style="font-family: Arial; line-height: 26px;" />
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px;"></p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px;">实际情况是，我们得到的ImageButton的大小是 33x27，很明显width被拉伸了，这是我们不想看到的情况。</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px;"><span style="color: #ff0000;"><strong>解决方案一：</strong></span></p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px;">代码中动态显式设置ImageButton的layout_width和layout_width，如下&nbsp;</p>
<div bg_java"="" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 927.015625px; overflow: auto; padding-top: 1px; line-height: 26px; margin: 18px 0px !important;">
<div style="padding-left: 45px;">
<div style="padding: 3px 8px 10px 10px; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: #f8f8f8; border-left-color: #6ce26c;"><strong>[java]</strong>&nbsp;<a href="http://blog.csdn.net/oathevil/article/details/23707359#" title="view plain" style="color: #a0a0a0; text-decoration: none; background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); background-color: inherit; border: none; padding: 1px; margin: 0px 10px 0px 0px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/oathevil/article/details/23707359#" title="copy" style="color: #a0a0a0; text-decoration: none; background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); background-color: inherit; border: none; padding: 1px; margin: 0px 10px 0px 0px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><a href="https://code.csdn.net/snippets/292476" target="_blank" title="在CODE上查看代码片" style="color: #a0a0a0; text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 1px; margin: 0px 10px 0px 0px; display: inline-block; width: 16px; height: 16px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;"><img src="https://code.csdn.net/assets/CODE_ico.png" width="12" height="12" alt="在CODE上查看代码片" style="border-style: none; max-width: 100%; position: relative; top: 1px; left: 2px;" /></a><a href="https://code.csdn.net/snippets/292476/fork" target="_blank" title="派生到我的代码片" style="color: #a0a0a0; text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 1px; margin: 0px 10px 0px 0px; display: inline-block; width: 16px; height: 16px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;"><img src="https://code.csdn.net/assets/ico_fork.svg" width="12" height="12" alt="派生到我的代码片" style="border-style: none; max-width: 100%; position: relative; top: 2px; left: 2px;" /></a>
<div style="position: absolute; left: 377px; top: 930px; width: 18px; height: 18px; z-index: 99;"><embed id="ZeroClipboardMovie_2" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="18" height="18" name="ZeroClipboardMovie_2" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=2&amp;width=18&amp;height=18" wmode="transparent"></div>
</div>
</div>
<ol start="1" style="padding: 0px; border: none; list-style-position: initial; list-style-image: initial; background-color: #ffffff; color: #5c5c5c; margin: 0px 0px 1px 45px !important;">
    <li style="border-style: none none none solid; border-left-width: 3px; border-left-color: #6ce26c; list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">LinearLayout.LayoutParams&nbsp;layoutParam&nbsp;=&nbsp;</span><span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">new</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;LinearLayout.LayoutParams(</span><span style="margin: 0px; padding: 0px; border: none; color: #c00000; background-color: inherit;">27</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">,&nbsp;</span><span style="margin: 0px; padding: 0px; border: none; color: #c00000; background-color: inherit;">27</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">);&nbsp;&nbsp;</span></span></li>
    <li style="border-style: none none none solid; border-left-width: 3px; border-left-color: #6ce26c; list-style: decimal-leading-zero outside; background-color: #f8f8f8; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">layout.addView(imageButton,&nbsp;layoutParam);&nbsp;&nbsp;</span></li>
</ol>
</div>
<span style="font-family: Arial; line-height: 26px;">不过，事实上我们并不希望在代码存在&#8220;硬编码&#8221;的情况。</span>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px;"></p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px;"><span style="color: #ff0000;"><strong>解决方案二：</strong></span></p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px;">在你通过setBackgroundResource()或者在xml设置android:background属性时，将你的background以XML Bitmap的形式定义，如下：</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px;"></p>
<div bg_html"="" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 927.015625px; overflow: auto; padding-top: 1px; line-height: 26px; margin: 18px 0px !important;">
<div style="padding-left: 45px;">
<div style="padding: 3px 8px 10px 10px; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: #f8f8f8; border-left-color: #6ce26c;"><strong>[html]</strong>&nbsp;<a href="http://blog.csdn.net/oathevil/article/details/23707359#" title="view plain" style="color: #a0a0a0; text-decoration: none; background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); background-color: inherit; border: none; padding: 1px; margin: 0px 10px 0px 0px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/oathevil/article/details/23707359#" title="copy" style="color: #a0a0a0; text-decoration: none; background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); background-color: inherit; border: none; padding: 1px; margin: 0px 10px 0px 0px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><a href="https://code.csdn.net/snippets/292476" target="_blank" title="在CODE上查看代码片" style="color: #a0a0a0; text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 1px; margin: 0px 10px 0px 0px; display: inline-block; width: 16px; height: 16px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;"><img src="https://code.csdn.net/assets/CODE_ico.png" width="12" height="12" alt="在CODE上查看代码片" style="border-style: none; max-width: 100%; position: relative; top: 1px; left: 2px;" /></a><a href="https://code.csdn.net/snippets/292476/fork" target="_blank" title="派生到我的代码片" style="color: #a0a0a0; text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 1px; margin: 0px 10px 0px 0px; display: inline-block; width: 16px; height: 16px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;"><img src="https://code.csdn.net/assets/ico_fork.svg" width="12" height="12" alt="派生到我的代码片" style="border-style: none; max-width: 100%; position: relative; top: 2px; left: 2px;" /></a>
<div style="position: absolute; left: 379px; top: 1116px; width: 18px; height: 18px; z-index: 99;"><embed id="ZeroClipboardMovie_3" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="18" height="18" name="ZeroClipboardMovie_3" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=3&amp;width=18&amp;height=18" wmode="transparent"></div>
</div>
</div>
<ol start="1" style="padding: 0px; border: none; list-style-position: initial; list-style-image: initial; background-color: #ffffff; color: #5c5c5c; margin: 0px 0px 1px 45px !important;">
    <li style="border-style: none none none solid; border-left-width: 3px; border-left-color: #6ce26c; list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">&lt;?</span><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">xml</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">version</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"1.0"</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">encoding</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"utf-8"</span><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">?&gt;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
    <li style="border-style: none none none solid; border-left-width: 3px; border-left-color: #6ce26c; list-style: decimal-leading-zero outside; background-color: #f8f8f8; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">&lt;</span><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">bitmap</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">xmlns:android</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"http://schemas.android.com/apk/res/android"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
    <li style="border-style: none none none solid; border-left-width: 3px; border-left-color: #6ce26c; list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">android:id</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"@id/toolbar_bg_bmp"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
    <li style="border-style: none none none solid; border-left-width: 3px; border-left-color: #6ce26c; list-style: decimal-leading-zero outside; background-color: #f8f8f8; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">android:src</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"@drawable/toolbar_bg"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
    <li style="border-style: none none none solid; border-left-width: 3px; border-left-color: #6ce26c; list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">android:tileMode</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"disabled"</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">android:gravity</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"top"</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">&gt;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
    <li style="border-style: none none none solid; border-left-width: 3px; border-left-color: #6ce26c; list-style: decimal-leading-zero outside; background-color: #f8f8f8; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">&lt;/</span><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">bitmap</span><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">&gt;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
</ol>
</div>
<span style="font-family: Arial; line-height: 26px;">调用如下：</span>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px;"></p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px;">&nbsp; &nbsp; imageButton.setBackgroundResource(R.drawable.toolbar_bg_bmp)</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px;">或者</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px;">&nbsp; &nbsp; &lt;ImageButton ... &nbsp;android:background="@drawable/toolbar_bg_bmp" ... /&gt;</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px;">若背景图片有多种状态，还可参照toolbar_bg_selector.xml：</p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px;"></p>
<div bg_html"="" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 927.015625px; overflow: auto; padding-top: 1px; line-height: 26px; margin: 18px 0px !important;">
<div style="padding-left: 45px;">
<div style="padding: 3px 8px 10px 10px; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: #f8f8f8; border-left-color: #6ce26c;"><strong>[html]</strong>&nbsp;<a href="http://blog.csdn.net/oathevil/article/details/23707359#" title="view plain" style="color: #a0a0a0; text-decoration: none; background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); background-color: inherit; border: none; padding: 1px; margin: 0px 10px 0px 0px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/oathevil/article/details/23707359#" title="copy" style="color: #a0a0a0; text-decoration: none; background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); background-color: inherit; border: none; padding: 1px; margin: 0px 10px 0px 0px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><a href="https://code.csdn.net/snippets/292476" target="_blank" title="在CODE上查看代码片" style="color: #a0a0a0; text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 1px; margin: 0px 10px 0px 0px; display: inline-block; width: 16px; height: 16px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;"><img src="https://code.csdn.net/assets/CODE_ico.png" width="12" height="12" alt="在CODE上查看代码片" style="border-style: none; max-width: 100%; position: relative; top: 1px; left: 2px;" /></a><a href="https://code.csdn.net/snippets/292476/fork" target="_blank" title="派生到我的代码片" style="color: #a0a0a0; text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 1px; margin: 0px 10px 0px 0px; display: inline-block; width: 16px; height: 16px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;"><img src="https://code.csdn.net/assets/ico_fork.svg" width="12" height="12" alt="派生到我的代码片" style="border-style: none; max-width: 100%; position: relative; top: 2px; left: 2px;" /></a>
<div style="position: absolute; left: 379px; top: 1426px; width: 18px; height: 18px; z-index: 99;"><embed id="ZeroClipboardMovie_4" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="18" height="18" name="ZeroClipboardMovie_4" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=4&amp;width=18&amp;height=18" wmode="transparent"></div>
</div>
</div>
<ol start="1" style="padding: 0px; border: none; list-style-position: initial; list-style-image: initial; background-color: #ffffff; color: #5c5c5c; margin: 0px 0px 1px 45px !important;">
    <li style="border-style: none none none solid; border-left-width: 3px; border-left-color: #6ce26c; list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">&lt;?</span><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">xml</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">version</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"1.0"</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">encoding</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"utf-8"</span><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">?&gt;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
    <li style="border-style: none none none solid; border-left-width: 3px; border-left-color: #6ce26c; list-style: decimal-leading-zero outside; background-color: #f8f8f8; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">&lt;</span><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">selector</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">xmlns:android</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"http://schemas.android.com/apk/res/android"</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">&gt;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
    <li style="border-style: none none none solid; border-left-width: 3px; border-left-color: #6ce26c; list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">&lt;</span><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">item</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">android:state_pressed</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"true"</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">&gt;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
    <li style="border-style: none none none solid; border-left-width: 3px; border-left-color: #6ce26c; list-style: decimal-leading-zero outside; background-color: #f8f8f8; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">&lt;</span><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">bitmap</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">android:src</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"@drawable/toolbar_bg_sel"</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">android:tileMode</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"disabled"</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">android:gravity</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"top"</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">/&gt;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
    <li style="border-style: none none none solid; border-left-width: 3px; border-left-color: #6ce26c; list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">&lt;/</span><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">item</span><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">&gt;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
    <li style="border-style: none none none solid; border-left-width: 3px; border-left-color: #6ce26c; list-style: decimal-leading-zero outside; background-color: #f8f8f8; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">&lt;</span><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">item</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">&gt;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
    <li style="border-style: none none none solid; border-left-width: 3px; border-left-color: #6ce26c; list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">&lt;</span><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">bitmap</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">android:src</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"@drawable/toolbar_bg"</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">android:tileMode</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"disabled"</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">android:gravity</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"top"</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">/&gt;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
    <li style="border-style: none none none solid; border-left-width: 3px; border-left-color: #6ce26c; list-style: decimal-leading-zero outside; background-color: #f8f8f8; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">&lt;/</span><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">item</span><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">&gt;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
    <li style="border-style: none none none solid; border-left-width: 3px; border-left-color: #6ce26c; list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">&lt;/</span><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">selector</span><span style="margin: 0px; padding: 0px; border: none; color: #993300; background-color: inherit; font-weight: bold;">&gt;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
</ol>
</div>
<br style="font-family: Arial; line-height: 26px;" />
<br style="font-family: Arial; line-height: 26px;" />
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px;"></p>
<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px;">如此，不管是通过代码方式setBackgroundResource()或XML android:background方式设置背景，均不会产生被拉伸的情况。</p>
@import url(http://www.blogjava.net/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.blogjava.net/jjshcc/aggbug/423105.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2015-03-01 00:31 <a href="http://www.blogjava.net/jjshcc/archive/2015/03/01/423105.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>查看Android中的AlarmManager事件</title><link>http://www.blogjava.net/jjshcc/archive/2015/01/06/422080.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Tue, 06 Jan 2015 07:26:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2015/01/06/422080.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/422080.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2015/01/06/422080.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/422080.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/422080.html</trackback:ping><description><![CDATA[<p style="box-sizing: border-box; margin: 0px 0px 18px; color: #333333; font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, STHeiti, sans-serif; line-height: 22.3999996185303px; background-color: #ffffff;">有时候我们需要设置一个alarmmanager事件<br style="box-sizing: border-box;" />但是如果这个事件的时间是凌晨三点 我们不可能等到凌晨三点吧<br style="box-sizing: border-box;" />adb中提供了查看alarmmanager的命令<br style="box-sizing: border-box;" /><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 2px 4px; color: #c7254e; border-radius: 3px; background-color: #f6f6f6;">adb shell dumpsys alarm</code><br style="box-sizing: border-box;" />通过这命令可以查看被放到定时队列里面的事件</p><pre hljs=""  bash"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 10px; margin-top: 18px; margin-bottom: 18px; line-height: 1.3; word-break: break-all; word-wrap: break-word; border: none; border-radius: 3px; position: relative; max-height: 500px; background: #f6f6f6;"><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;">    RTC_WAKEUP <span style="box-sizing: border-box; color: #888888;">#1: Alarm{52c2ad84 type 0 com.sina.weibo}</span>     <span style="box-sizing: border-box; font-weight: bold;">type</span>=<span style="box-sizing: border-box; color: #008800;">0</span> when=+<span style="box-sizing: border-box; color: #008800;">3</span>m1s330ms repeatInterval=<span style="box-sizing: border-box; color: #008800;">0</span> count=<span style="box-sizing: border-box; color: #008800;">0</span>     operation=PendingIntent{<span style="box-sizing: border-box; color: #008800;">529</span>fa514: PendingIntentRecord{<span style="box-sizing: border-box; color: #008800;">52</span>a7b220 com.sina.weibo broadcastIntent}} </code></pre><p style="box-sizing: border-box; margin: 18px 0px; color: #333333; font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, STHeiti, sans-serif; line-height: 22.3999996185303px; background-color: #ffffff;">如果我们就可以看到其中一个微博的alarm 如果我们想看他intent的详细信息<br style="box-sizing: border-box;" />就可以用下面这个命令<br style="box-sizing: border-box;" /><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 2px 4px; color: #c7254e; border-radius: 3px; background-color: #f6f6f6;">adb shell dumpsys activity intents</code><br style="box-sizing: border-box;" />然后找到里面id是52a7b220 的那一段</p><pre hljs=""  bash"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 0.92857em; padding: 10px; margin-top: 18px; margin-bottom: 18px; line-height: 1.3; word-break: break-all; word-wrap: break-word; border: none; border-radius: 3px; position: relative; max-height: 500px; background: #f6f6f6;"><code style="box-sizing: border-box; font-family: Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; padding: 0px; color: inherit; border-radius: 0px; white-space: pre-wrap; background-color: transparent;">  * PendingIntentRecord{<span style="box-sizing: border-box; color: #008800;">52</span>a7b220 com.sina.weibo broadcastIntent}     uid=<span style="box-sizing: border-box; color: #008800;">10073</span> packageName=com.sina.weibo <span style="box-sizing: border-box; font-weight: bold;">type</span>=broadcastIntent flags=<span style="box-sizing: border-box; color: #008800;">0</span>x0     requestCode=<span style="box-sizing: border-box; color: #008800;">1383195892</span> requestResolvedType=null     requestIntent=act=AlarmTaskSchedule     sent=<span style="box-sizing: border-box; color: #008800;">true</span> canceled=<span style="box-sizing: border-box; color: #008800;">false</span></code></pre><img src ="http://www.blogjava.net/jjshcc/aggbug/422080.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2015-01-06 15:26 <a href="http://www.blogjava.net/jjshcc/archive/2015/01/06/422080.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>AlarmManager使用简介</title><link>http://www.blogjava.net/jjshcc/archive/2015/01/05/422063.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Mon, 05 Jan 2015 08:59:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2015/01/05/422063.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/422063.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2015/01/05/422063.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/422063.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/422063.html</trackback:ping><description><![CDATA[<div>&nbsp;</div><div>1、AlarmManager，顾名思义，就是&#8220;提醒&#8221;，是Android中常用的一种系统级别的提示服务，在特定的时刻为我们广播一个指定的Intent。简单的说就是我们设定一个时间，然后在该时间到来时，AlarmManager为我们广播一个我们设定的Intent,通常我们使用 PendingIntent，PendingIntent可以理解为Intent的封装包，简单的说就是在Intent上在加个指定的动作。在使用Intent的时候，我们还需要在执行startActivity、startService或sendBroadcast才能使Intent有用。而PendingIntent的话就是将这个动作包含在内了。</div><div></div><div>定义一个PendingIntent对象。</div><div>PendingIntent pi = PendingIntent.getBroadcast(this,0,intent,0);</div><div></div><div>2、AlarmManager的常用方法有三个：</div><div></div><div>（1）set(int type，long startTime，PendingIntent pi)；</div><div></div><div>该方法用于设置一次性闹钟，第一个参数表示闹钟类型，第二个参数表示闹钟执行时间，第三个参数表示闹钟响应动作。</div><div></div><div>（2）setRepeating(int type，long startTime，long intervalTime，PendingIntent pi)；</div><div></div><div>该方法用于设置重复闹钟，第一个参数表示闹钟类型，第二个参数表示闹钟首次执行时间，第三个参数表示闹钟两次执行的间隔时间，第三个参数表示闹钟响应动作。</div><div></div><div>（3）setInexactRepeating（int type，long startTime，long intervalTime，PendingIntent pi）；</div><div></div><div>该方法也用于设置重复闹钟，与第二个方法相似，不过其两个闹钟执行的间隔时间不是固定的而已。</div><div></div><div>3、三个方法各个参数详悉：</div><div></div><div>（1）int type： 闹钟的类型，常用的有5个值：AlarmManager.ELAPSED_REALTIME、 AlarmManager.ELAPSED_REALTIME_WAKEUP、AlarmManager.RTC、 AlarmManager.RTC_WAKEUP、AlarmManager.POWER_OFF_WAKEUP。</div><div></div><div>AlarmManager.ELAPSED_REALTIME表示闹钟在手机睡眠状态下不可用，该状态下闹钟使用相对时间（相对于系统启动开始），状态值为3；</div><div></div><div>AlarmManager.ELAPSED_REALTIME_WAKEUP表示闹钟在睡眠状态下会唤醒系统并执行提示功能，该状态下闹钟也使用相对时间，状态值为2；</div><div></div><div>AlarmManager.RTC表示闹钟在睡眠状态下不可用，该状态下闹钟使用绝对时间，即当前系统时间，状态值为1；</div><div></div><div>AlarmManager.RTC_WAKEUP表示闹钟在睡眠状态下会唤醒系统并执行提示功能，该状态下闹钟使用绝对时间，状态值为0；</div><div></div><div>AlarmManager.POWER_OFF_WAKEUP表示闹钟在手机关机状态下也能正常进行提示功能，所以是5个状态中用的最多的状态之一，该状态下闹钟也是用绝对时间，状态值为4；不过本状态好像受SDK版本影响，某些版本并不支持；</div><div></div><div>（2）long startTime： 闹钟的第一次执行时间，以毫秒为单位，可以自定义时间，不过一般使用当前时间。需要注意的是，本属性与第一个属性（type）密切相关，如果第一个参数对 应的闹钟使用的是相对时间（ELAPSED_REALTIME和ELAPSED_REALTIME_WAKEUP），那么本属性就得使用相对时间（相对于 系统启动时间来说），比如当前时间就表示为：SystemClock.elapsedRealtime()；如果第一个参数对应的闹钟使用的是绝对时间 （RTC、RTC_WAKEUP、POWER_OFF_WAKEUP），那么本属性就得使用绝对时间，比如当前时间就表示 为：System.currentTimeMillis()。</div><div></div><div>（3）long intervalTime：对于后两个方法来说，存在本属性，表示两次闹钟执行的间隔时间，也是以毫秒为单位。</div><div></div><div>（4）PendingIntent pi： 绑定了闹钟的执行动作，比如发送一个广播、给出提示等等。PendingIntent是Intent的封装类。需要注意的是，如果是通过启动服务来实现闹钟提 示的话，PendingIntent对象的获取就应该采用Pending.getService(Context c,int i,Intent intent,int j)方法；如果是通过广播来实现闹钟提示的话，PendingIntent对象的获取就应该采用 PendingIntent.getBroadcast(Context c,int i,Intent intent,int j)方法；如果是采用Activity的方式来实现闹钟提示的话，PendingIntent对象的获取就应该采用 PendingIntent.getActivity(Context c,int i,Intent intent,int j)方法。如果这三种方法错用了的话，虽然不会报错，但是看不到闹钟提示效果。</div><div></div><div>4.举例说明：定义一个闹钟，5秒钟重复响应。</div><div></div><div>（1）MainActivity，在onCreate中完成：</div><div></div><div></div><div>&nbsp;</div><div>&nbsp;//创建Intent对象，action为ELITOR_CLOCK，附加信息为字符串&#8220;你该打酱油了&#8221; &nbsp;&nbsp;</div><div>&nbsp;Intent intent = new Intent("ELITOR_CLOCK"); &nbsp;</div><div>&nbsp;intent.putExtra("msg","你该打酱油了"); &nbsp; &nbsp;</div><div>&nbsp; &nbsp;</div><div>&nbsp;//定义一个PendingIntent对象，PendingIntent.getBroadcast包含了sendBroadcast的动作。 &nbsp;&nbsp;</div><div>&nbsp;//也就是发送了action 为"ELITOR_CLOCK"的intent &nbsp;&nbsp;</div><div>&nbsp;PendingIntent pi = PendingIntent.getBroadcast(this,0,intent,0); &nbsp; &nbsp;</div><div>&nbsp; &nbsp;</div><div>&nbsp;//AlarmManager对象,注意这里并不是new一个对象，Alarmmanager为系统级服务 &nbsp;&nbsp;</div><div>&nbsp; AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE); &nbsp; &nbsp;</div><div>&nbsp; &nbsp;&nbsp;</div><div>&nbsp; /设置闹钟从当前时间开始，每隔5s执行一次PendingIntent对象pi，注意第一个参数与第二个参数的关系 &nbsp;&nbsp;</div><div>&nbsp;// 5秒后通过PendingIntent pi对象发送广播 &nbsp;&nbsp;</div><div>&nbsp;am.setRepeating(AlarmManager.RTC_WAKEUP,System.currentTimeMillis(),5*1000,pi); &nbsp;</div><div></div><div></div><div></div><div>那么启动MainActivity之后，由于定义了AlarmManager am，并且调用了am.setRepeating(...)函数,则系统每隔5s将会通过pi启动intent发送广播，其action为ELITOR_CLOCK。所以我们需要在Manifest.xml中注册一个receiver,同时自己定义一个广播接收器类。</div><div></div><div>(2)定义一个广播接收器类MyReceiver，重写onReceive()函数。</div><div></div><div></div><div>&nbsp;</div><div>public class MyReceiver extends BroadcastReceiver &nbsp;</div><div>{ &nbsp;</div><div>&nbsp;&nbsp;</div><div>&nbsp; &nbsp; @Override &nbsp;</div><div>&nbsp; &nbsp; public void onReceive(Context context, Intent intent) &nbsp;</div><div>&nbsp; &nbsp; { &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; // TODO Auto-generated method stub &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; Log.d("MyTag", "onclock......................"); &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; String msg = intent.getStringExtra("msg"); &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Toast.makeText(context,msg,Toast.LENGTH_SHORT).show(); &nbsp;</div><div>&nbsp; &nbsp; &nbsp;} &nbsp;</div><div>&nbsp; &nbsp;</div><div>&nbsp;} &nbsp;</div><div></div><div></div><div></div><div></div><div>（3）在Manifest.xml中注册广播接收器：</div><div></div><div></div><div>&nbsp;</div><div>&nbsp;&lt;receiver android:name=".MyReceiver"&gt; &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;intent-filter&gt; &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;action android:name="ELITOR_CLOCK" /&gt; &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/intent-filter&gt; &nbsp;</div><div>&nbsp;&lt;/receiver&gt; &nbsp;</div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div>&nbsp;</div><div></div><div>&nbsp;</div><div>&nbsp;</div><div>&nbsp;</div><div></div><img src ="http://www.blogjava.net/jjshcc/aggbug/422063.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2015-01-05 16:59 <a href="http://www.blogjava.net/jjshcc/archive/2015/01/05/422063.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Android SQLite3工具常用命令行总结</title><link>http://www.blogjava.net/jjshcc/archive/2014/12/30/421960.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Tue, 30 Dec 2014 07:40:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2014/12/30/421960.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/421960.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2014/12/30/421960.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/421960.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/421960.html</trackback:ping><description><![CDATA[<p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #f5f5f5;"><span style="margin: 0px; padding: 0px; font-size: 14px;">Android SDK的tools目录下提供了一个sqlite3.exe工具，这是一个简单的sqlite数据库管理工具。开发者可以方便的使用其对sqlite数据库进行命令行的操作。</span></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #f5f5f5;"><span style="margin: 0px; padding: 0px; font-size: 14px;">程序运行生成的*.db文件一般位于"/data/data/项目名(包括所处包名)/databases/*.db"，因此要对数据库文件进行操作需要先找到数据库文件：</span></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #f5f5f5;"><span style="margin: 0px; padding: 0px; font-size: 14px;">1、进入shell 命令</span></p><pre name="code" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-size: 13px; line-height: 19.5px; background-color: #f5f5f5;">adb shell</pre><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #f5f5f5;">2、找到数据库文件</p><pre name="code" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-size: 13px; line-height: 19.5px; background-color: #f5f5f5;">#cd data/data #ls                --列出所有项目 #cd project_name   --进入所需项目名 #cd databases     #ls                --列出现寸的数据库文件</pre><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #f5f5f5;">3、进入数据库</p><pre name="code" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-size: 13px; line-height: 19.5px; background-color: #f5f5f5;">#sqlite3 test_db   --进入所需数据库</pre><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #f5f5f5;">会出现类似如下字样：</p><pre name="code" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-size: 13px; line-height: 19.5px; background-color: #f5f5f5;">SQLite version 3.6.22 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite&gt;</pre><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #f5f5f5;">至此，可对数据库进行操作。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #f5f5f5;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #f5f5f5;"><span style="margin: 0px; padding: 0px; font-size: 14px;">4、sqlite常用命令</span></p><pre name="code" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-size: 13px; line-height: 19.5px; background-color: #f5f5f5;">&gt;.databases        --产看当前数据库 &gt;.tables           --查看当前数据库中的表 &gt;.help             --sqlite3帮助 &gt;.schema            --各个表的生成语句</pre><img src ="http://www.blogjava.net/jjshcc/aggbug/421960.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2014-12-30 15:40 <a href="http://www.blogjava.net/jjshcc/archive/2014/12/30/421960.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Android LayoutInflater详解</title><link>http://www.blogjava.net/jjshcc/archive/2014/12/17/421488.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Wed, 17 Dec 2014 02:23:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2014/12/17/421488.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/421488.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2014/12/17/421488.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/421488.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/421488.html</trackback:ping><description><![CDATA[<div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">在实际开发中LayoutInflater这个类还是非常有用的，它的作用类似于findViewById()。不同点是LayoutInflater是用来找res/layout/下的xml布局文件，并且实例化；而findViewById()是找xml布局文件下的具体widget控件(如Button、TextView等)。</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">具体作用：</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">1、对于一个没有被载入或者想要动态载入的界面，都需要使用LayoutInflater.inflate()来载入；</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">2、对于一个已经载入的界面，就可以使用Activiyt.findViewById()方法来获得其中的界面元素。</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">LayoutInflater 是一个抽象类，在文档中如下声明：</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">public abstract class LayoutInflater extends Object</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">获得 LayoutInflater 实例的三种方式</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">1. LayoutInflater inflater = getLayoutInflater();//调用Activity的getLayoutInflater()&nbsp;</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">2. LayoutInflater inflater = LayoutInflater.from(context); &nbsp;</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">3. LayoutInflater inflater = &nbsp;(LayoutInflater)context.getSystemService</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (Context.LAYOUT_INFLATER_SERVICE);</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">其实，这三种方式本质是相同的，从源码中可以看出：</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">getLayoutInflater()：</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">Activity 的 getLayoutInflater() 方法是调用 PhoneWindow 的getLayoutInflater()方法，看一下该源代码：</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">public PhoneWindow(Context context)</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">{ &nbsp;&nbsp;</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">&nbsp;super(context); &nbsp;&nbsp;</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">&nbsp; &nbsp; mLayoutInflater = LayoutInflater.from(context);</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">}</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">可以看出它其实是调用 LayoutInflater.from(context)。</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">LayoutInflater.from(context)：</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">public static LayoutInflater from(Context context)</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">{ &nbsp;&nbsp;</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">&nbsp;LayoutInflater LayoutInflater = (LayoutInflater) context.getSystemService</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(Context.LAYOUT_INFLATER_SERVICE);</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">&nbsp; &nbsp; if (LayoutInflater == null)</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">&nbsp; &nbsp; { &nbsp; &nbsp; &nbsp;&nbsp;</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">&nbsp; &nbsp; &nbsp;throw new AssertionError("LayoutInflater not found."); &nbsp;&nbsp;</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">&nbsp; &nbsp; } &nbsp;&nbsp;</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">&nbsp; &nbsp; return LayoutInflater;</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">}</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">可以看出它其实调用 context.getSystemService()。</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">结论：所以这三种方式最终本质是都是调用的Context.getSystemService()。</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">另外getSystemService()是Android很重要的一个API，它是Activity的一个方法，根据传入的NAME来取得对应的Object，然后转换成相应的服务对象。以下介绍系统相应的服务。</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">&nbsp;</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">传入的Name&nbsp;<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>返回的对象<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>说明</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">WINDOW_SERVICE<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>WindowManager<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>管理打开的窗口程序</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">LAYOUT_INFLATER_SERVICE<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>LayoutInflater<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>取得xml里定义的view</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">ACTIVITY_SERVICE<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>ActivityManager<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>管理应用程序的系统状态</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">POWER_SERVICE<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>PowerManger<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>电源的服务</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">ALARM_SERVICE<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>AlarmManager<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>闹钟的服务</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">NOTIFICATION_SERVICE<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>NotificationManager<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>状态栏的服务</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">KEYGUARD_SERVICE<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>KeyguardManager<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>键盘锁的服务</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">LOCATION_SERVICE<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>LocationManager<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>位置的服务，如GPS</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">SEARCH_SERVICE<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>SearchManager<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>搜索的服务</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">VEBRATOR_SERVICE<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>Vebrator<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>手机震动的服务</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">CONNECTIVITY_SERVICE<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>Connectivity<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>网络连接的服务</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">WIFI_SERVICE<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>WifiManager<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>Wi-Fi服务</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">TELEPHONY_SERVICE<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>TeleponyManager<span style="margin: 0px; padding: 0px; white-space: pre;">	</span>电话服务</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">inflate 方法</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">通过 sdk 的 api 文档，可以知道该方法有以下几种过载形式，返回值均是 View 对象，如下：</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">public View inflate (int resource, ViewGroup root)&nbsp;</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">public View inflate (XmlPullParser parser, ViewGroup root)</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">public View inflate (XmlPullParser parser, ViewGroup root, boolean attachToRoot) &nbsp;</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">public View inflate (int resource, ViewGroup root, boolean attachToRoot)</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">示意代码：</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE); &nbsp; &nbsp; &nbsp;&nbsp;</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">View view = inflater.inflate(R.layout.custom, (ViewGroup)findViewById(R.id.test)); &nbsp; &nbsp; &nbsp;&nbsp;</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">//EditText editText = (EditText)findViewById(R.id.content);// error&nbsp;</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">EditText editText = (EditText)view.findViewById(R.id.content);</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">对于上面代码，指定了第二个参数 ViewGroup root，当然你也可以设置为 null 值。</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">注意：</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">&#183;inflate 方法与 findViewById 方法不同；</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">&#183;inflater 是用来找 res/layout 下的 xml 布局文件，并且实例化；</div><div style="margin: 0px; color: #666666; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #dddddd;">&#183;findViewById() 是找具体 xml 布局文件中的具体 widget 控件(如:Button、TextView 等)。</div><img src ="http://www.blogjava.net/jjshcc/aggbug/421488.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2014-12-17 10:23 <a href="http://www.blogjava.net/jjshcc/archive/2014/12/17/421488.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>android自定义弹出框样式实现</title><link>http://www.blogjava.net/jjshcc/archive/2014/12/16/421476.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Tue, 16 Dec 2014 09:24:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2014/12/16/421476.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/421476.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2014/12/16/421476.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/421476.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/421476.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 做项目时，感觉android自带的弹出框样式比较丑，很多应用都是自己做的弹出框，这里也试着自己做了一个。废话不说先上图片：实现机制1.先自定义一个弹出框的样式2.自己实现CustomDialog类，继承自Dialog，实现里面方法，在里面加载自定义样式的弹出框；3.使用时，与使用Dialog一样具体代码dialog_normal_layout.xml样式文件[html]&nbsp;view pla...&nbsp;&nbsp;<a href='http://www.blogjava.net/jjshcc/archive/2014/12/16/421476.html'>阅读全文</a><img src ="http://www.blogjava.net/jjshcc/aggbug/421476.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2014-12-16 17:24 <a href="http://www.blogjava.net/jjshcc/archive/2014/12/16/421476.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>LinearLayout中组件右对齐</title><link>http://www.blogjava.net/jjshcc/archive/2014/12/16/421469.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Tue, 16 Dec 2014 07:42:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2014/12/16/421469.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/421469.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2014/12/16/421469.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/421469.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/421469.html</trackback:ping><description><![CDATA[<p style="color: #333333; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.2000007629395px; background-color: #ffffff;">在LinearLayout中，如果将其定位方向设为横向排列：android:orientation="horizontal"，那么这个布局中的控件将自左向右排列。</p><p style="color: #333333; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.2000007629395px; background-color: #ffffff;">但有时会有这样的情况：行的左边有两个控制的同时，行的右边也有一个控制。</p><p style="color: #333333; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.2000007629395px; background-color: #ffffff;">如图：<img alt="" style="border: 0px; max-width: 100%;" /></p><p style="color: #333333; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.2000007629395px; background-color: #ffffff;">这怎么处理呢？</p><p style="color: #333333; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.2000007629395px; background-color: #ffffff;">我们可以将右边的控件放在另一个LinearLayout中,同时将其对齐方式设为右对齐：android:gravity="right"，还有一点，这个LinearLayout的宽度设为充满父控件： android:layout_width="fill_parent"。这样就行了。</p><p style="color: #333333; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.2000007629395px; background-color: #ffffff;">完整的XML代码如下：</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; width: 679px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; margin-left: 9px; color: #333333; word-break: break-all; word-wrap: break-word; line-height: 25.2000007629395px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; font-weight: bold; margin: 0px;">Xml代码&nbsp;&nbsp;<a href="http://blog.csdn.net/hhq163/article/details/8372482" title="收藏这段代码" style="color: #108ac6; padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat;"><img src="http://chenjinbo1983.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px; max-width: 100%;" /></a></div></div><ol start="1" style="margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af; font-size: 1em; line-height: 1.4em;"><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;"><span style="color: #006699; font-weight: bold;">&lt;?</span><span style="color: #006699; font-weight: bold;">xml</span>&nbsp;<span style="color: red;">version</span>=<span style="color: blue;">"1.0"</span>&nbsp;<span style="color: red;">encoding</span>=<span style="color: blue;">"utf-8"</span><span style="color: #006699; font-weight: bold;">?&gt;</span>&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;"><span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">LinearLayout</span>&nbsp;<span style="color: red;">xmlns:android</span>=<span style="color: blue;">"http://schemas.android.com/apk/res/android"</span>&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">android:layout_width</span>=<span style="color: blue;">"fill_parent"</span>&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">android:layout_height</span>=<span style="color: blue;">"fill_parent"</span>&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">android:background</span>=<span style="color: blue;">"@drawable/bg"</span>&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">android:orientation</span>=<span style="color: blue;">"horizontal"</span>&nbsp;<span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">TextView</span>&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">android:layout_width</span>=<span style="color: blue;">"wrap_content"</span>&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">android:layout_height</span>=<span style="color: blue;">"wrap_content"</span>&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">android:text</span>=<span style="color: blue;">"左边1"</span>&nbsp;<span style="color: #006699; font-weight: bold;">/&gt;</span>&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">TextView</span>&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">android:layout_width</span>=<span style="color: blue;">"wrap_content"</span>&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">android:layout_height</span>=<span style="color: blue;">"wrap_content"</span>&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">android:text</span>=<span style="color: blue;">"左边2"</span>&nbsp;<span style="color: #006699; font-weight: bold;">/&gt;</span>&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&nbsp;将TextView包在另一个LinearLayout中&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注意android:layout_width和android:gravity这两个属性&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--<span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">LinearLayout</span>&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">android:layout_width</span>=<span style="color: blue;">"fill_parent"</span>&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">android:layout_height</span>=<span style="color: blue;">"wrap_content"</span>&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">android:gravity</span>=<span style="color: blue;">"right"</span>&nbsp;<span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">TextView</span>&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">android:layout_width</span>=<span style="color: blue;">"wrap_content"</span>&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">android:layout_height</span>=<span style="color: blue;">"wrap_content"</span>&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">android:layout_marginRight</span>=<span style="color: blue;">"10dp"</span>&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">android:text</span>=<span style="color: blue;">"右边"</span>&nbsp;<span style="color: #006699; font-weight: bold;">/&gt;</span>&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">LinearLayout</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;">&nbsp;&nbsp;</li><li style="margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; font-size: 1em; background-color: #fafafa;"><span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">LinearLayout</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li></ol></div><img src ="http://www.blogjava.net/jjshcc/aggbug/421469.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2014-12-16 15:42 <a href="http://www.blogjava.net/jjshcc/archive/2014/12/16/421469.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>android 自定义控件 使用declare-styleable进行配置属性（源码角度）</title><link>http://www.blogjava.net/jjshcc/archive/2014/12/16/421454.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Tue, 16 Dec 2014 04:43:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2014/12/16/421454.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/421454.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2014/12/16/421454.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/421454.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/421454.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: declare-styleable：declare-styleable是给自定义控件添加自定义属性用的。官方的相关内部控件的配置属性文档：http://developer.android.com/reference/android/R.styleable.html如果不知道如何查看源码：点击这里起初，在自定义控件的时候，会要求构造3个方法中的一个或多个，好比我自定义的控件PersonView，[j...&nbsp;&nbsp;<a href='http://www.blogjava.net/jjshcc/archive/2014/12/16/421454.html'>阅读全文</a><img src ="http://www.blogjava.net/jjshcc/aggbug/421454.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2014-12-16 12:43 <a href="http://www.blogjava.net/jjshcc/archive/2014/12/16/421454.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>android如何设置控件的样式</title><link>http://www.blogjava.net/jjshcc/archive/2014/12/16/421453.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Tue, 16 Dec 2014 03:57:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2014/12/16/421453.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/421453.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2014/12/16/421453.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/421453.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/421453.html</trackback:ping><description><![CDATA[<p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 19.5px; font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #fefef2;">有时候我们不满足于系统控件的外观要改变一些背景，文字颜色等，这些属性可以在代码里更改，随便哪种控件，我们点，后面会出来一大串set开头的方法。但是在代码里这样改来改去还是比较麻烦的，如果同样的控件多了，重复的代码也比较多。控件的这些属性也是可以在xml文件里改的，同样的控件多了，还是会带来代码的重复。这进我们就可以用设置控件样子式的方法了。下面以EditText控件为例来说明如何来设置一个控件的样式，工程序源码可以在后面下载;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 19.5px; font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #fefef2;">第一步建立一个新的工程，在main布局里面建立三个EditText控件。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 19.5px; font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #fefef2;">第二步在工程的res/values文件夹下新建一个xml文件内容如下：<br /></p><div class="cnblogs_code" style="margin: 5px 0px; font-size: 12px !important;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&lt;?</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff00ff;">xml version="1.0" encoding="utf-8"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">?&gt;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&lt;</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #800000;">resources</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&gt;</span><br style="margin: 0px; padding: 0px;" />    <span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&lt;</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #800000;">style </span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;">name</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="et1"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;"> parent</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="@android:style/Widget.EditText"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&gt;</span><br style="margin: 0px; padding: 0px;" />        <span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&lt;</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #800000;">item </span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;">name</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="android:background"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&gt;</span>#1A4EA4<span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&lt;/</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #800000;">item</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&gt;</span><br style="margin: 0px; padding: 0px;" />        <span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&lt;</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #800000;">item </span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;">name</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="android:textColor"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&gt;</span>#FFF111<span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&lt;/</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #800000;">item</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&gt;</span><br style="margin: 0px; padding: 0px;" />    <span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&lt;/</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #800000;">style</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&gt;</span><br style="margin: 0px; padding: 0px;" />        <span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&lt;</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #800000;">style </span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;">name</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="et2"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;"> parent</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="@android:style/Widget.EditText"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&gt;</span><br style="margin: 0px; padding: 0px;" />        <span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&lt;</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #800000;">item </span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;">name</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="android:background"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&gt;</span>#A6C60F<span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&lt;/</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #800000;">item</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&gt;</span><br style="margin: 0px; padding: 0px;" />        <span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&lt;</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #800000;">item </span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;">name</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="android:textColor"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&gt;</span>#EC02C3<span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&lt;/</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #800000;">item</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&gt;</span><br style="margin: 0px; padding: 0px;" />    <span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&lt;/</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #800000;">style</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&gt;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&lt;/</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #800000;">resources</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&gt;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #008000;">&lt;!--</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #008000;"><br style="margin: 0px; padding: 0px;" />说明：<br style="margin: 0px; padding: 0px;" />    这里建立了两种样式，从字面意思上可以看出这两中样式分别都更改了背景颜色和文字颜色<br style="margin: 0px; padding: 0px;" />，一个控件可以更改的属性有很多，这里只改了两个，要改其它的属性，我们要知道属性的name,<br style="margin: 0px; padding: 0px;" />才可以改。那所有的属性的名字在哪呢？找了一番终于找到了，所有的属性的名字在一个attrs.xml<br style="margin: 0px; padding: 0px;" />文件里。这个文件存在于：android sdk目录\data\res\values 目录下，找到这个文件以后我们<br style="margin: 0px; padding: 0px;" />改某些属性时可以做为查看的资料了。<br style="margin: 0px; padding: 0px;" />    上面的两个样式中，都有一个parent属性。这就不难理解style是可以继承的。在这里我们继<br style="margin: 0px; padding: 0px;" />承的是系统默认的EditText属性，只修改了背景和文字颜色而已。那系统的EditText样式是在哪<br style="margin: 0px; padding: 0px;" />定义的呢？找了一番终于也找到了，所有系统控件的样式是在一个style.xml文件中，这个文件也<br style="margin: 0px; padding: 0px;" />在上面说的那个目录下。里面我们可以找到Widget.EditText的样式定义。有了它我们也可以查看<br style="margin: 0px; padding: 0px;" />某一种控件可以更改哪些样式了。<br style="margin: 0px; padding: 0px;" />    在设置style时，我们经常用到@和？@表明引用的的资源是在一个项目或是系统框架中定义过<br style="margin: 0px; padding: 0px;" />的。？表明引用的资源是在当前的主题定义过的。<br style="margin: 0px; padding: 0px;" />    上面的设置背景中的值除了可以是颜色的值外，还可以是一个图片的引用哦~~。<br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" /></span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #008000;">--&gt;</span></pre><div class="cnblogs_code_toolbar" style="margin: 5px 0px 0px;"><span class="cnblogs_code_copy" style="margin: 0px; padding: 0px 5px 0px 0px; line-height: 1.5;"><a title="复制代码" style="margin: 0px; padding: 0px; color: #075db3; text-decoration: underline; border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin: 0px; padding: 0px; border: none !important;" /></a></span></div></div><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 19.5px; font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #fefef2;"><br /></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 19.5px; font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #fefef2;"><br style="margin: 0px; padding: 0px;" />&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 19.5px; font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #fefef2;">第三步我们修改main布局文件中EditText的属性。为了对比，我们将第一个属性将做改变，第二个的style属性设为我们上面建立的name为et1的样式。第三个的style属性设为我们上面建立的name为et2的样式，代码如下：</p><div style="margin: 5px 0px; font-size: 12px !important;"><div style="margin: 5px 0px 0px;"><span style="margin: 0px; padding: 0px 5px 0px 0px; line-height: 1.5;"><a title="复制代码" style="margin: 0px; padding: 0px; color: #075db3; text-decoration: underline; border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin: 0px; padding: 0px; border: none !important;" /></a></span></div><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&lt;?</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff00ff;">xml version="1.0" encoding="utf-8"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">?&gt;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&lt;</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #800000;">LinearLayout </span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;">xmlns:android</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="http://schemas.android.com/apk/res/android"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;"><br style="margin: 0px; padding: 0px;" />    android:layout_width</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="fill_parent"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;"> android:layout_height</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="fill_parent"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;"><br style="margin: 0px; padding: 0px;" />    android:orientation</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="vertical"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&gt;</span><br style="margin: 0px; padding: 0px;" />    <span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&lt;</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #800000;">EditText </span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;">android:layout_width</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="fill_parent"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;"><br style="margin: 0px; padding: 0px;" />        android:layout_height</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="wrap_content"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;"> android:text</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="默认样式"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;"> android:id</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="@+id/et1"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&gt;&lt;/</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #800000;">EditText</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&gt;</span><br style="margin: 0px; padding: 0px;" />    <span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&lt;</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #800000;">EditText </span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;">android:layout_width</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="fill_parent"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;"> android:id</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="@+id/et2"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;"><br style="margin: 0px; padding: 0px;" />        android:text</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="自定义样式一"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;"> android:layout_height</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="wrap_content"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;"> style</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="@style/et1"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&gt;&lt;/</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #800000;">EditText</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&gt;</span><br style="margin: 0px; padding: 0px;" />    <span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&lt;</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #800000;">EditText </span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;">android:layout_width</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="fill_parent"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;"> android:id</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="@+id/et3"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;"><br style="margin: 0px; padding: 0px;" />        android:text</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="自定义样式二"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;"> android:layout_height</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="wrap_content"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;"> style</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="@style/et2"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&gt;&lt;/</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #800000;">EditText</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&gt;</span><br style="margin: 0px; padding: 0px;" />    <span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&lt;</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #800000;">Button </span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;">android:text</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="改变主题"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;"> android:id</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="@+id/btn1"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;"><br style="margin: 0px; padding: 0px;" />        android:layout_width</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="fill_parent"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;"> android:layout_height</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">="wrap_content"</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&gt;&lt;/</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #800000;">Button</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&gt;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&lt;/</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #800000;">LinearLayout</span><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #0000ff;">&gt;</span></pre><div style="margin: 5px 0px 0px;"><span style="margin: 0px; padding: 0px 5px 0px 0px; line-height: 1.5;"><a title="复制代码" style="margin: 0px; padding: 0px; color: #075db3; text-decoration: underline; border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin: 0px; padding: 0px; border: none !important;" /></a></span></div></div><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 19.5px; font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #fefef2;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 19.5px; font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #fefef2;">&nbsp;加了一个改变主题的按钮是无效的，下一篇会用到它来设置主题。虽然定义好了style文件，但似乎并不能在java代码里设置，我没有发现像setStyle()这样的方法。所以就不 能在java代码里能过style文件动态改变控件的样式， 不知道哪位仁兄可以解决此问题，特在此求教了。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 19.5px; font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #fefef2;">&nbsp;无图无真相，下面是截图：</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 19.5px; font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #fefef2;"><img src="http://pic002.cnblogs.com/images/2011/177283/2011101807580328.png" alt="" style="margin: 0px; padding: 0px; border: 0px;" /></p><img src ="http://www.blogjava.net/jjshcc/aggbug/421453.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2014-12-16 11:57 <a href="http://www.blogjava.net/jjshcc/archive/2014/12/16/421453.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Android布局的长度单位</title><link>http://www.blogjava.net/jjshcc/archive/2014/12/16/421451.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Tue, 16 Dec 2014 03:38:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2014/12/16/421451.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/421451.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2014/12/16/421451.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/421451.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/421451.html</trackback:ping><description><![CDATA[<p style="font-family: 'Times New Roman'; font-size: medium; line-height: normal;">&nbsp; Android中布局的单位很多，如：（dp、sp、px、in、pt、mm）&nbsp;但是他们之间有什么区别了？又该在什么时候使用了？我想即使是很有经验的开发者有时也会不明白吧。</p><p style="font-family: 'Times New Roman'; font-size: medium; line-height: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 现在这里介绍一下dp和sp。dp也就是dip。这个和sp基本类似。如果设置表示长度、高度等属性时可以使用dp 或sp。但如果设置字体，需要使用sp。dp是与密度无关，sp除了与密度无关外，还与scale无关。如果屏幕密度为160，这时dp和sp和px是一样的。1dp=1sp=1px，但如果使用px作单位，如果屏幕大小不变（假设还是3.2寸），而屏幕密度变成了320。那么原来TextView的宽度设成160px，在密度为320的3.2寸屏幕里看要比在密度为160的3.2寸屏幕上看短了一半。但如果设置成160dp或160sp的话。系统会自动将width属性值设置成320px的。也就是160 * 320 / 160。其中320 / 160可称为密度比例因子。也就是说，如果使用dp和sp，系统会根据屏幕密度的变化自动进行转换。</p><p style="font-family: 'Times New Roman'; font-size: medium; line-height: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; px：表示屏幕实际的象素。例如，320*480的屏幕在横向有320个象素，在纵向有480个象素。&nbsp;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; in：表示英寸，是屏幕的物理尺寸。每英寸等于2.54厘米。例如，形容手机屏幕大小，经常说，3.2（英）寸、3.5（英）寸、4（英）寸就是指这个单位。这些尺寸是屏幕的对角线长度。如果手机的屏幕是3.2英寸，表示手机的屏幕（可视区域）对角线长度是3.2*2.54 = 8.128厘米。读者可以去量一量自己的手机屏幕，看和实际的尺寸是否一致。&nbsp;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mm：表示毫米，是屏幕的物理尺寸。&nbsp;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pt：表示一个点，是屏幕的物理尺寸。大小为1英寸的1/72。<br /></p><img src ="http://www.blogjava.net/jjshcc/aggbug/421451.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2014-12-16 11:38 <a href="http://www.blogjava.net/jjshcc/archive/2014/12/16/421451.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Android SDK无法更新,hosts解决</title><link>http://www.blogjava.net/jjshcc/archive/2014/12/16/421448.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Tue, 16 Dec 2014 03:16:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2014/12/16/421448.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/421448.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2014/12/16/421448.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/421448.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/421448.html</trackback:ping><description><![CDATA[<p style="margin: 0px 0px 10px; padding: 0px; border: 0px; font-size: 13px; font-family: 'Microsoft YaHei', 微软雅黑, Arial, 'Lucida Grande', Tahoma, sans-serif; line-height: 24.0499992370605px; background: #ffffff;">Windows<br />修改 C:\Windows\System32\drivers\etc\hosts</p><p style="margin: 0px 0px 10px; padding: 0px; border: 0px; font-size: 13px; font-family: 'Microsoft YaHei', 微软雅黑, Arial, 'Lucida Grande', Tahoma, sans-serif; line-height: 24.0499992370605px; background: #ffffff;">Linux/Mac<br />修改 /etc/hosts</p><p style="margin: 0px 0px 10px; padding: 0px; border: 0px; font-size: 13px; font-family: 'Microsoft YaHei', 微软雅黑, Arial, 'Lucida Grande', Tahoma, sans-serif; line-height: 24.0499992370605px; background: #ffffff;">在最后添加一行:<br />74.125.237.1 dl-ssl.google.com</p><p style="margin: 0px 0px 10px; padding: 0px; border: 0px; font-size: 13px; font-family: 'Microsoft YaHei', 微软雅黑, Arial, 'Lucida Grande', Tahoma, sans-serif; line-height: 24.0499992370605px; background: #ffffff;">原理就是：我们输入网站时，一般都是通过DNS 域名解析。<br />但是顺序为：先读取 hosts 文件，是否有对应的IP，若有直接通过此IP访问。没有的话，就通过 DNS 解析到的 IP 访问，但是GOOGLE，在内地是没有服务器的，一般解析不到的。</p><img src ="http://www.blogjava.net/jjshcc/aggbug/421448.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2014-12-16 11:16 <a href="http://www.blogjava.net/jjshcc/archive/2014/12/16/421448.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Android之Activity的几种跳转方式</title><link>http://www.blogjava.net/jjshcc/archive/2014/11/25/420557.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Tue, 25 Nov 2014 05:20:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2014/11/25/420557.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/420557.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2014/11/25/420557.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/420557.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/420557.html</trackback:ping><description><![CDATA[<span style="margin: 0px; padding: 0px; border: 0px; font-size: 13px; font-family: 'Microsoft YaHei', 微软雅黑, Arial, 'Lucida Grande', Tahoma, sans-serif; line-height: 24.0499992370605px; background: #ffffff;">&nbsp; &nbsp;</span><strong style="font-family: 'Microsoft YaHei', 微软雅黑, Arial, 'Lucida Grande', Tahoma, sans-serif; font-size: 13px; line-height: 24.0499992370605px; background-color: #ffffff;">&nbsp;1.显示调用方法<br /></strong><div style="margin: 0px; border: 0px; font-size: 13px; color: #4e6384; font-family: 'Microsoft YaHei', 微软雅黑, Arial, 'Lucida Grande', Tahoma, sans-serif; line-height: 23px; background: #ffffff;"><ul style="margin: 0px 0px 10px; padding: 0px; border: 0px; list-style: none; background: transparent;"><li style="list-style: square inside; line-height: 26px;">Intent intent=new Intent(this,OtherActivity.class); &nbsp;//方法1</li></ul><ul style="margin: 0px 0px 10px; padding: 0px; border: 0px; list-style: none; background: transparent;"><li style="list-style: square inside; line-height: 26px;">Intent intent2=new Intent();</li></ul><ul style="margin: 0px 0px 10px; padding: 0px; border: 0px; list-style: none; background: transparent;"><li style="list-style: square inside; line-height: 26px;">intent2.setClass(this, OtherActivity.class);//方法2</li><li style="list-style: square inside; line-height: 26px;">intent2.setClassName(this, "com.zy.MutiActivity.OtherActivity"); &nbsp;//方法3 此方式可用于打开其它的应用</li><li style="list-style: square inside; line-height: 26px;">intent2.setComponent(new ComponentName(this, OtherActivity.class)); &nbsp;//方法4</li><li style="list-style: square inside; line-height: 26px;">startActivity(intent2);</li></ul><div style="margin: 0px; border: 0px; background: transparent;">&nbsp;</div><div style="margin: 0px; border: 0px; background: transparent;"><strong>2.隐式调用方法（只要action、category、data和要跳转到的Activity在AndroidManifest.xml中设置的匹配就OK</strong></div></div><div style="margin: 0px; border: 0px; font-size: 13px; color: #4e6384; font-family: 'Microsoft YaHei', 微软雅黑, Arial, 'Lucida Grande', Tahoma, sans-serif; line-height: 23px; background: #ffffff;"><img src="http://images.cnitblog.com/blog/465866/201305/02132849-67e3d8d25b614a92a7d30cd8600c454d.png" alt="" original="http://images.cnitblog.com/blog/465866/201305/02132849-67e3d8d25b614a92a7d30cd8600c454d.png" style="margin: 0px; padding: 0px; border: 0px; background: transparent;" /></div><div style="margin: 0px; border: 0px; font-size: 13px; color: #4e6384; font-family: 'Microsoft YaHei', 微软雅黑, Arial, 'Lucida Grande', Tahoma, sans-serif; line-height: 23px; background: #ffffff;"><img src="file:///C:/Users/AllenZheng/AppData/Local/youdao/ynote/images/62721903A5E14B40ABF2B229AF3556D1/clipboard.png" alt="" data-media-type="image" data-inited="true" original="file:///C:/Users/AllenZheng/AppData/Local/youdao/ynote/images/62721903A5E14B40ABF2B229AF3556D1/clipboard.png" style="margin: 0px; padding: 0px; border: 0px; background: transparent;" /></div><div style="margin: 0px; border: 0px; font-size: 13px; color: #4e6384; font-family: 'Microsoft YaHei', 微软雅黑, Arial, 'Lucida Grande', Tahoma, sans-serif; line-height: 23px; background: #ffffff;">&nbsp;</div><div style="margin: 0px; border: 0px; font-size: 13px; color: #4e6384; font-family: 'Microsoft YaHei', 微软雅黑, Arial, 'Lucida Grande', Tahoma, sans-serif; line-height: 23px; background: #ffffff;"><strong>3.跳转到另一个Activity后，当返回时能返回数据</strong></div><div style="margin: 0px; border: 0px; font-size: 13px; color: #4e6384; font-family: 'Microsoft YaHei', 微软雅黑, Arial, 'Lucida Grande', Tahoma, sans-serif; line-height: 23px; background: #ffffff;"><ul style="margin: 0px 0px 10px; padding: 0px; border: 0px; list-style: none; background: transparent;"><li style="list-style: square inside; line-height: 26px;">在跳转的Activity端，调用startActivityForResult(intent2, 1),跳转到下一个Activity，其中第一个参数为传入的意图对象，第二个为设置的请求码；</li><li style="list-style: square inside; line-height: 26px;">跳转到第二个Activity后，调用setResult(100, intent)方法可返回上一个Activity，其中第一个参数为结果码，第二个为传入的意图对象；</li><li style="list-style: square inside; line-height: 26px;">在第一个Activity通过onActivityResult()方法获得返回的数据。</li></ul></div><img src ="http://www.blogjava.net/jjshcc/aggbug/420557.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2014-11-25 13:20 <a href="http://www.blogjava.net/jjshcc/archive/2014/11/25/420557.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>让Android模拟器飞一会，模拟器的速度终于可以快过真机啦！</title><link>http://www.blogjava.net/jjshcc/archive/2014/11/24/420500.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Mon, 24 Nov 2014 03:46:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2014/11/24/420500.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/420500.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2014/11/24/420500.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/420500.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/420500.html</trackback:ping><description><![CDATA[<p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;"><span style="color: #e53333;">PS：有的人安装过程中遇到这个问题this computer meets the reauirements for HAXM,but....</span></p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;"><img src="http://static.oschina.net/uploads/space/2013/0201/135104_llcT_945990.jpg" alt="" /></p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;"><span style="color: #e53333;">这个问题应该是CPU可能默认没有开Vt，所以得去bios开了再说。进了bios找到virtual technology选项，选择enable即可。</span></p><div style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;"></div><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;"><br /></p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;"><strong style="background-color: #ffff66;">android</strong>的<strong style="background-color: #ff9999;">模拟器</strong>一直以来是它的一大败笔，启动需要很长时间，运行起来也超慢，虽说可以通过创建<strong style="background-color: #ff9999;">模拟器</strong>时更改参数，但速度还是不理想。所以，以前开发时，一直用<a name="baidusnap1"></a><strong style="background-color: #a0ffff;">真机调试</strong>，可它的接口又是那么的脆弱，用不了多久，就接触不良了，这个问题一直困扰很多人。之前发现过一种方法，可以通过WIFI调试，但是需要有无线路由器，而且很多手机对这个支持不太好。前几天同事分享了一种方法(API guid里面有讲)，可以让<strong style="background-color: #ff9999;">模拟器</strong>在X86架构的机器上以原生的速度运行。</p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;">方法很简单：</p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;">1.通过<strong style="background-color: #ffff66;">android</strong>&nbsp;sdk manager下载" Intel Hardware Accelerated Execution Manager"，下载完成后，在SDK目录中找到下载文件并安装它。</p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;">2.通过<strong style="background-color: #ffff66;">android</strong>&nbsp;sdk manager 下载 &#8220;Intel x86 Atom System Image</p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;">3.创建Intel x86的<strong style="background-color: #ff9999;">模拟器</strong>。</p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;">下面就可以使用创建的这个x86的<strong style="background-color: #ff9999;">模拟器</strong>进行调试了，速度非常<strong style="color: white; background-color: #880000;">快</strong>，我用的MacBook装的WIN7，启动<strong style="background-color: #ff9999;">模拟器</strong>只需要几秒，运行APP速度跟我的三星I9001一样流畅，需要注意的是：</p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;">1.<strong style="background-color: #ffff66;">android</strong>&nbsp;sdk tools 至少要R17以上，<strong style="background-color: #ffff66;">android</strong>&nbsp;sdk API 至少要15</p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;">2.自己的电脑要给力，我的<strong style="background-color: #ff9999;">模拟器</strong>给它分了2G的内存，所以速度特别<strong style="color: white; background-color: #880000;">快</strong>。</p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;">不上图了，下面是文档地址：<a href="http://developer.android.com/tools/devices/emulator.html" rel="nofollow">http://developer.<strong style="color: black; background-color: #ffff66;">android</strong>.com/tools/devices/emulator.html</a></p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;"><br /></p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;">首先打开sdk manager，确定有x86的image。如下图</p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;">4.2只有ARM的image，所以不好使，还得用4.1.2的(2013年1月31日，4.2版本已有x86的image)</p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;"><img alt="" src="http://static.oschina.net/uploads/img/201301/31224613_1Tjg.png" /></p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;"><br /></p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;">然后下载一下intelHAXM</p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;"><img alt="" src="http://static.oschina.net/uploads/img/201301/31224613_W8o9.png" /></p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;">然后进到sdk\extras\intel\Hardware_Accelerated_Execution_Manager去点击exe，一路next安装一下。</p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;"><img alt="" src="http://static.oschina.net/uploads/img/201301/31224613_oGWW.png" /></p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;"><br /></p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;">为了确认是否开了，打开命令行 输入</p><pre style="line-height: normal;">sc query intelhaxm</pre><span style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;">然后像下面State 是running就对了。</span><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;"><img alt="" src="http://static.oschina.net/uploads/img/201301/31224614_ojMV.png" /></p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;"><br /></p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;">CPU可能默认没有开Vt，所以得去bios开了再说。</p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;"><br /></p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;">然后建立AVD</p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;">cpu/abi的地方记得选x86的</p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;">然后下面的Hardware部分要new一下，搞出来GPU emulation 然后选择yes</p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;"><img alt="" src="http://static.oschina.net/uploads/img/201301/31224614_MWsa.png" /></p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;"><span style="color: #e53333;">更新了adt到21.0.1后，创建AVD的界面有些不同。如下图，在Emulation Options里要选上Use Host GPU.</span></p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;"><img src="http://static.oschina.net/uploads/space/2013/0201/140744_Wx0S_945990.png" alt="" /></p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;">然后就可以了，启动AVD</p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;"><img alt="" src="http://static.oschina.net/uploads/img/201301/31224614_ECXY.png" /></p><p style="font-family: Verdana, sans-serif, 宋体; font-size: medium; line-height: normal;">显示HAX is working。</p><img src ="http://www.blogjava.net/jjshcc/aggbug/420500.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2014-11-24 11:46 <a href="http://www.blogjava.net/jjshcc/archive/2014/11/24/420500.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>android 使用虚拟机安装apk(图文教程)</title><link>http://www.blogjava.net/jjshcc/archive/2014/06/27/415168.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Fri, 27 Jun 2014 03:22:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2014/06/27/415168.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/415168.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2014/06/27/415168.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/415168.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/415168.html</trackback:ping><description><![CDATA[<div><span style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25px; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 5px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; font-size: 14px; ">1、启动虚拟机</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 5px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; font-size: 14px; ">2、我的android sdk在&#8220;E:\android\android开发环境\android SDK\platform-tools&#8221;把要安装的apk复制到这个根目录（和adb.exe同文件夹）。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 5px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; font-size: 14px; ">2、点击电脑左下角的&#8220;开始&#8221;按钮，输入cmd然后点击回车打开cmd输入框。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 5px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; font-size: 14px; ">3、<span style="line-height: 18px; font-size: 14px; display: inline !important; float: none; word-spacing: 0px; font: normal normal normal 12px/18px Verdana, 宋体; text-transform: none; color: #121c46; text-indent: 24px; white-space: normal; letter-spacing: normal; background-color: #ffffff; orphans: 2; widows: 2; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; ">&nbsp;(由于我的Android SDK安装路径为e盘，所以需要定位模拟器platform-tools目录) 在cmd命令提示符中输入E: 回车，如图 第一行</span>，</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 5px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; font-size: 14px; ">4、apk名称为zq7.1.1.apk</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 5px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; font-size: 14px; "><img alt="" src="http://files.jb51.net/file_images/article/201212/201212311628386.png" width="620" height="413" title="在新窗口打开图片" style="border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-width: initial; border-color: initial; border-top-width: 1px; border-left-width: 1px; border-bottom-width: 1px; border-right-width: 1px; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 3px; padding-right: 3px; padding-bottom: 3px; padding-left: 3px; max-width: 620px; overflow-x: hidden; overflow-y: hidden; " /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 5px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; font-size: 14px; ">这样就安装成功了</p></span></div><img src ="http://www.blogjava.net/jjshcc/aggbug/415168.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2014-06-27 11:22 <a href="http://www.blogjava.net/jjshcc/archive/2014/06/27/415168.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在android 中使用og4j</title><link>http://www.blogjava.net/jjshcc/archive/2013/06/07/400349.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Fri, 07 Jun 2013 06:02:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2013/06/07/400349.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/400349.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2013/06/07/400349.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/400349.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/400349.html</trackback:ping><description><![CDATA[<div id="nei" class="article_body">
<div property="content:encoded">
<p>Android is a Linux-based operating system designed primarily for touchscreen mobile devices such as smartphones and tablet computers, developed by Google in conjunction with the Open Handset Alliance. The Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language. Apache log4j is a logging library for Java and an Apache Software Foundation Project and developed by a dedicated team of Committers of the Apache Software Foundation. Here we will explain how to integrate Log4J in Android based Java applications.</p>
<h3>Step 1</h3>
<p>Download Log4J library from <a href="http://logging.apache.org/log4j/1.2/download.html">http://logging.apache.org/log4j/1.2/download.html</a> </p>
<h3>Step 2</h3>
<p>Configuring Log4J library the normal way - using XML configuration file - can't be used in Android based Java application as the configuration classes of Log4J use beans from the package "java.beans" (e.g. PropertyDescriptor). Not all classes of this package are supported in Android, so using Log4J directly in Android Java application will case exceptions like the following one to be thrown:</p>
<p>11-23 09:44:56.947: D/dalvikvm(1585): GC_FOR_MALLOC freed 3278 objects / 311568 bytes in 31ms <br />rejecting opcode 0x21 at 0x000a <br />rejected Lorg/apache/log4j/config/PropertySetter;.getPropertyDescriptor <br />(Ljava/lang/String;)Ljava/beans/PropertyDescriptor; <br />Verifier rejected class Lorg/apache/log4j/config/PropertySetter; <br />Exception Ljava/lang/VerifyError; thrown during Lorg/apache/log4j/LogManager;. <br />Shutting down VM <br />threadid=1: thread exiting with uncaught exception (group=0x400259f8) <br />FATAL EXCEPTION: main <br />java.lang.ExceptionInInitializerError <br />at org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:64) <br />at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:253) <br />at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:265) <br />... <br />Caused by: java.lang.VerifyError: org.apache.log4j.config.PropertySetter <br />at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:772) <br />at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:735) <br />at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:615) <br />at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:502) <br />at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:547) <br />at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:483) <br />at org.apache.log4j.LogManager.(LogManager.java:127) <br />... 20 more </p>
<p>There is a project called android-logging-log4j, which provides a convenient way to configure the log4j system properly.</p>
<p>Download "Android Logging Log4J" library from <a href="http://code.google.com/p/android-logging-log4j/downloads/list">http://code.google.com/p/android-logging-log4j/downloads/list</a> </p>
<h3>Step 3</h3>
<p>Add Both libraries "log4j" and "android-logging-log4j" to your application libraries</p>
<h3>Step 4</h3>
<p>In order to log to a file on the external storage, the following permission needs to be placed in <strong>AndroidManifest.xml</strong> </p>
<div>
<div style="font-family: monospace">
<ol><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal"><span style="color: #009900"><span style="color: #000000; font-weight: bold">&lt;uses-permission</span> <span style="color: #000066">android:name</span> = <span style="color: #ff0000">"android.permission.WRITE_EXTERNAL_STORAGE"</span> <span style="color: #000000; font-weight: bold">/&gt;</span> </span></div></li></ol></div></div>
<h3>Step 5</h3>
<p>In your application Main class:</p>
<div>
<div style="font-family: monospace">
<ol><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal"><span style="color: #000000; font-weight: bold">package</span> <span style="color: #006699">com.android.myapp</span> <span style="color: #339933">;</span> </div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal">&nbsp;</div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal"><span style="color: #000000; font-weight: bold">import</span> <span style="color: #006699">java.io.File</span> <span style="color: #339933">;</span> </div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal">&nbsp;</div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal"><span style="color: #000000; font-weight: bold">import</span> <span style="color: #006699">org.apache.log4j.Level</span> <span style="color: #339933">;</span> </div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal"><span style="color: #000000; font-weight: bold">import</span> <span style="color: #006699">org.apache.log4j.Logger</span> <span style="color: #339933">;</span> </div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal">&nbsp;</div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal"><span style="color: #000000; font-weight: bold">import</span> <span style="color: #006699">android.app.Application</span> <span style="color: #339933">;</span> </div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal"><span style="color: #000000; font-weight: bold">import</span> <span style="color: #006699">android.os.Environment</span> <span style="color: #339933">;</span> </div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal"><span style="color: #000000; font-weight: bold">import</span> <span style="color: #006699">de.mindpipe.android.logging.log4j.LogConfigurator</span> <span style="color: #339933">;</span> </div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal">&nbsp;</div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal"><span style="color: #000000; font-weight: bold">public</span> <span style="color: #000000; font-weight: bold">class</span> MyApplication <span style="color: #000000; font-weight: bold">extends</span> Application <span style="color: #009900">{</span> </div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal">&nbsp; &nbsp; &nbsp; &nbsp; @Override</div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold">public</span> <span style="color: #000066; font-weight: bold">void</span> onCreate <span style="color: #009900">(</span> <span style="color: #009900">)</span> <span style="color: #009900">{</span> </div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold">super</span> . <span style="color: #006633">onCreate</span> <span style="color: #009900">(</span> <span style="color: #009900">)</span> <span style="color: #339933">;</span> </div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LogConfigurator logConfigurator <span style="color: #339933">=</span> <span style="color: #000000; font-weight: bold">new</span> LogConfigurator <span style="color: #009900">(</span> <span style="color: #009900">)</span> <span style="color: #339933">;</span> </div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logConfigurator. <span style="color: #006633">setFileName</span> <span style="color: #009900">(</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocs.oracle.com+javase+docs+api+environment"><span style="color: #003399">Environment</span> </a>. <span style="color: #006633">getExternalStorageDirectory</span> <span style="color: #009900">(</span> <span style="color: #009900">)</span> </div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933">+</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocs.oracle.com+javase+docs+api+file"><span style="color: #003399">File</span> </a>. <span style="color: #006633">separator</span> <span style="color: #339933">+</span> <span style="color: #0000ff">"MyApp"</span> <span style="color: #339933">+</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocs.oracle.com+javase+docs+api+file"><span style="color: #003399">File</span> </a>. <span style="color: #006633">separator</span> <span style="color: #339933">+</span> <span style="color: #0000ff">"logs"</span> </div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933">+</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocs.oracle.com+javase+docs+api+file"><span style="color: #003399">File</span> </a>. <span style="color: #006633">separator</span> <span style="color: #339933">+</span> <span style="color: #0000ff">"log4j.txt"</span> <span style="color: #009900">)</span> <span style="color: #339933">;</span> </div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logConfigurator. <span style="color: #006633">setRootLevel</span> <span style="color: #009900">(</span> Level. <span style="color: #006633">DEBUG</span> <span style="color: #009900">)</span> <span style="color: #339933">;</span> </div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logConfigurator. <span style="color: #006633">setLevel</span> <span style="color: #009900">(</span> <span style="color: #0000ff">"org.apache"</span> , Level. <span style="color: #006633">ERROR</span> <span style="color: #009900">)</span> <span style="color: #339933">;</span> </div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logConfigurator. <span style="color: #006633">setFilePattern</span> <span style="color: #009900">(</span> <span style="color: #0000ff">"%d %-5p [%c{2}]-[%L] %m%n"</span> <span style="color: #009900">)</span> <span style="color: #339933">;</span> </div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logConfigurator. <span style="color: #006633">setMaxFileSize</span> <span style="color: #009900">(</span> <span style="color: #cc66cc">1024</span> <span style="color: #339933">*</span> <span style="color: #cc66cc">1024</span> <span style="color: #339933">*</span> <span style="color: #cc66cc">5</span> <span style="color: #009900">)</span> <span style="color: #339933">;</span> </div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logConfigurator. <span style="color: #006633">setImmediateFlush</span> <span style="color: #009900">(</span> <span style="color: #000066; font-weight: bold">true</span> <span style="color: #009900">)</span> <span style="color: #339933">;</span> </div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logConfigurator. <span style="color: #006633">configure</span> <span style="color: #009900">(</span> <span style="color: #009900">)</span> <span style="color: #339933">;</span> </div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Logger log <span style="color: #339933">=</span> Logger. <span style="color: #006633">getLogger</span> <span style="color: #009900">(</span> MyApplication. <span style="color: #000000; font-weight: bold">class</span> <span style="color: #009900">)</span> <span style="color: #339933">;</span> </div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log. <span style="color: #006633">info</span> <span style="color: #009900">(</span> <span style="color: #0000ff">"My Application Created"</span> <span style="color: #009900">)</span> <span style="color: #339933">;</span> </div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900">}</span> </div></li><li>
<div style="font-style: normal; font-family: monospace; font-weight: normal"><span style="color: #009900">}</span> </div></li></ol></div></div>
<p>Now you will have log4j configured to log to Path: (Environment.getExternalStorageDirectory() + File.separator + "MyApp" + File.separator + "logs" + File.separator + "log4j.txt") with DEBUG level and ERROR lever for "org.apache" package with file pattern "%d %-5p [%c{2}]-[%L] %m%n" and other configuration parameters</p></div></div><img src ="http://www.blogjava.net/jjshcc/aggbug/400349.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2013-06-07 14:02 <a href="http://www.blogjava.net/jjshcc/archive/2013/06/07/400349.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>unicode转中文 </title><link>http://www.blogjava.net/jjshcc/archive/2012/04/26/376711.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Thu, 26 Apr 2012 09:44:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2012/04/26/376711.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/376711.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2012/04/26/376711.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/376711.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/376711.html</trackback:ping><description><![CDATA[<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img id="Codehighlighter1_53_1474_Open_Image" onclick="this.style.display='none'; Codehighlighter1_53_1474_Open_Text.style.display='none'; Codehighlighter1_53_1474_Closed_Image.style.display='inline'; Codehighlighter1_53_1474_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_53_1474_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_53_1474_Closed_Text.style.display='none'; Codehighlighter1_53_1474_Open_Image.style.display='inline'; Codehighlighter1_53_1474_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top"><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;String&nbsp;decodeUnicode(String&nbsp;theString)&nbsp;</span><span id="Codehighlighter1_53_1474_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_53_1474_Open_Text"><span style="color: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;aChar;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;len&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;theString.length();<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;StringBuffer&nbsp;outBuffer&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;StringBuffer(len);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img id="Codehighlighter1_183_1438_Open_Image" onclick="this.style.display='none'; Codehighlighter1_183_1438_Open_Text.style.display='none'; Codehighlighter1_183_1438_Closed_Image.style.display='inline'; Codehighlighter1_183_1438_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_183_1438_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_183_1438_Closed_Text.style.display='none'; Codehighlighter1_183_1438_Open_Image.style.display='inline'; Codehighlighter1_183_1438_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;x&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;x&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;len;)&nbsp;</span><span id="Codehighlighter1_183_1438_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_183_1438_Open_Text"><span style="color: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aChar&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;theString.charAt(x</span><span style="color: #000000">++</span><span style="color: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img id="Codehighlighter1_245_1398_Open_Image" onclick="this.style.display='none'; Codehighlighter1_245_1398_Open_Text.style.display='none'; Codehighlighter1_245_1398_Closed_Image.style.display='inline'; Codehighlighter1_245_1398_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_245_1398_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_245_1398_Closed_Text.style.display='none'; Codehighlighter1_245_1398_Open_Image.style.display='inline'; Codehighlighter1_245_1398_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(aChar&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">\\</span><span style="color: #000000">'</span><span style="color: #000000">)&nbsp;</span><span id="Codehighlighter1_245_1398_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_245_1398_Open_Text"><span style="color: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aChar&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;theString.charAt(x</span><span style="color: #000000">++</span><span style="color: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img id="Codehighlighter1_306_1152_Open_Image" onclick="this.style.display='none'; Codehighlighter1_306_1152_Open_Text.style.display='none'; Codehighlighter1_306_1152_Closed_Image.style.display='inline'; Codehighlighter1_306_1152_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_306_1152_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_306_1152_Closed_Text.style.display='none'; Codehighlighter1_306_1152_Open_Image.style.display='inline'; Codehighlighter1_306_1152_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(aChar&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">u</span><span style="color: #000000">'</span><span style="color: #000000">)&nbsp;</span><span id="Codehighlighter1_306_1152_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_306_1152_Open_Text"><span style="color: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;Read&nbsp;the&nbsp;xxxx</span><span style="color: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;value&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img id="Codehighlighter1_386_1109_Open_Image" onclick="this.style.display='none'; Codehighlighter1_386_1109_Open_Text.style.display='none'; Codehighlighter1_386_1109_Closed_Image.style.display='inline'; Codehighlighter1_386_1109_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_386_1109_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_386_1109_Closed_Text.style.display='none'; Codehighlighter1_386_1109_Open_Image.style.display='inline'; Codehighlighter1_386_1109_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">4</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)&nbsp;</span><span id="Codehighlighter1_386_1109_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_386_1109_Open_Text"><span style="color: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aChar&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;theString.charAt(x</span><span style="color: #000000">++</span><span style="color: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img id="Codehighlighter1_448_1101_Open_Image" onclick="this.style.display='none'; Codehighlighter1_448_1101_Open_Text.style.display='none'; Codehighlighter1_448_1101_Closed_Image.style.display='inline'; Codehighlighter1_448_1101_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_448_1101_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_448_1101_Closed_Text.style.display='none'; Codehighlighter1_448_1101_Open_Image.style.display='inline'; Codehighlighter1_448_1101_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">switch</span><span style="color: #000000">&nbsp;(aChar)&nbsp;</span><span id="Codehighlighter1_448_1101_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_448_1101_Open_Text"><span style="color: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">0</span><span style="color: #000000">'</span><span style="color: #000000">:<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">1</span><span style="color: #000000">'</span><span style="color: #000000">:<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">2</span><span style="color: #000000">'</span><span style="color: #000000">:<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">3</span><span style="color: #000000">'</span><span style="color: #000000">:<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">4</span><span style="color: #000000">'</span><span style="color: #000000">:<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">5</span><span style="color: #000000">'</span><span style="color: #000000">:<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">6</span><span style="color: #000000">'</span><span style="color: #000000">:<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">7</span><span style="color: #000000">'</span><span style="color: #000000">:<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">8</span><span style="color: #000000">'</span><span style="color: #000000">:<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">9</span><span style="color: #000000">'</span><span style="color: #000000">:<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(value&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">4</span><span style="color: #000000">)&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;aChar&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">0</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">a</span><span style="color: #000000">'</span><span style="color: #000000">:<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">b</span><span style="color: #000000">'</span><span style="color: #000000">:<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">c</span><span style="color: #000000">'</span><span style="color: #000000">:<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">d</span><span style="color: #000000">'</span><span style="color: #000000">:<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">e</span><span style="color: #000000">'</span><span style="color: #000000">:<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">f</span><span style="color: #000000">'</span><span style="color: #000000">:<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(value&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">4</span><span style="color: #000000">)&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">10</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;aChar&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">a</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">A</span><span style="color: #000000">'</span><span style="color: #000000">:<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">B</span><span style="color: #000000">'</span><span style="color: #000000">:<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">C</span><span style="color: #000000">'</span><span style="color: #000000">:<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">D</span><span style="color: #000000">'</span><span style="color: #000000">:<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">E</span><span style="color: #000000">'</span><span style="color: #000000">:<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">F</span><span style="color: #000000">'</span><span style="color: #000000">:<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(value&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">4</span><span style="color: #000000">)&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">10</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;aChar&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">A</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">default</span><span style="color: #000000">:<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">throw</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;IllegalArgumentException(<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">Malformed&nbsp;&nbsp;&nbsp;\\uxxxx&nbsp;&nbsp;&nbsp;encoding.</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;outBuffer.append((</span><span style="color: #0000ff">char</span><span style="color: #000000">)&nbsp;value);<br /><img id="Codehighlighter1_1159_1392_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1159_1392_Open_Text.style.display='none'; Codehighlighter1_1159_1392_Closed_Image.style.display='inline'; Codehighlighter1_1159_1392_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_1159_1392_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1159_1392_Closed_Text.style.display='none'; Codehighlighter1_1159_1392_Open_Image.style.display='inline'; Codehighlighter1_1159_1392_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span id="Codehighlighter1_1159_1392_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1159_1392_Open_Text"><span style="color: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(aChar&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">t</span><span style="color: #000000">'</span><span style="color: #000000">)<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aChar&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">\t</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(aChar&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">r</span><span style="color: #000000">'</span><span style="color: #000000">)<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aChar&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">\r</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(aChar&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">n</span><span style="color: #000000">'</span><span style="color: #000000">)<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aChar&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">\n</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(aChar&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">f</span><span style="color: #000000">'</span><span style="color: #000000">)<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aChar&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">\f</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;outBuffer.append(aChar);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;outBuffer.append(aChar);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;outBuffer.toString();<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /></span></div><img src ="http://www.blogjava.net/jjshcc/aggbug/376711.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2012-04-26 17:44 <a href="http://www.blogjava.net/jjshcc/archive/2012/04/26/376711.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Android 基于GeolocationAPI的基站定位</title><link>http://www.blogjava.net/jjshcc/archive/2012/04/23/376369.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Mon, 23 Apr 2012 06:48:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2012/04/23/376369.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/376369.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2012/04/23/376369.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/376369.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/376369.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->import&nbsp;java.io.BufferedReader;&nbsp;import&nbsp;java.io.InputStream;&nbsp;import&nbsp;java.io.Inp...&nbsp;&nbsp;<a href='http://www.blogjava.net/jjshcc/archive/2012/04/23/376369.html'>阅读全文</a><img src ="http://www.blogjava.net/jjshcc/aggbug/376369.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2012-04-23 14:48 <a href="http://www.blogjava.net/jjshcc/archive/2012/04/23/376369.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Android真机调试方法</title><link>http://www.blogjava.net/jjshcc/archive/2012/04/17/374854.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Tue, 17 Apr 2012 01:39:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2012/04/17/374854.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/374854.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2012/04/17/374854.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/374854.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/374854.html</trackback:ping><description><![CDATA[<p>1. 设置android手机为USB调试模式。步骤：设置&gt; 应用程序&gt; 开发&gt;选择USB调试;</p>
<p>2. 用USB连接手机和电脑，并确保成功。步骤： 在<a class="keylink" href="http://www.2cto.com/os/windows/" target="_blank">windows</a>下执行c:adb devices， 查看手机是否已经连接成功；</p>
<p>&nbsp;3. 设置应用程序为调试模式。操作： 编辑AndroidManifest.xml 增加调试参数android:debuggable="true", 如下：</p>
<p>&lt;application android:icon="@drawable/icon"&nbsp; android:label="@string/app_name" android:debuggable="true"&gt;</p>
<p>&nbsp;4. 执行真机调试操作：ECLIPSE调试对话框中，Target窗口中选择Manual，点击debug按钮，选择真机设备，开始调试。</p>
<p>注：不管是否启用ECLIPSE环境，任何Android软件只要在真机上运行发生异常，都可以在命令行窗口下查看具体异常信息：</p>
<p>&nbsp;执行：.adb logcat 可以查看到更多的系统异常消息。在这些消息中要注意查看Caused by:打 头的行，这些行指明了在哪行代码出的错误。</p><img src ="http://www.blogjava.net/jjshcc/aggbug/374854.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2012-04-17 09:39 <a href="http://www.blogjava.net/jjshcc/archive/2012/04/17/374854.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>如何检查Android后台服务线程（Service类）是否正在运行</title><link>http://www.blogjava.net/jjshcc/archive/2012/04/11/373827.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Wed, 11 Apr 2012 09:33:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2012/04/11/373827.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/373827.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2012/04/11/373827.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/373827.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/373827.html</trackback:ping><description><![CDATA[<p>描述： 
<p><span style="font-size: 14px">如何检查后台服务（Android的Service类）是否正在运行？我希望我的Activity能够显示Service的状态，然后我可以打开或者关闭它。</span></p>
<p>&nbsp;</p>
<p>回答： 
<p><span style="font-size: 14px">Android系统提供了一个函数ActivityManager.getRunningServices可以列出当前正在运行的后台服务线程<br /><br /><span style="background-color: rgb(230,230,250)">private boolean isServiceRunning() {</span><br /><span style="background-color: rgb(230,230,250)">&nbsp;&nbsp;&nbsp; ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);</span><br /><span style="background-color: rgb(230,230,250)">&nbsp;&nbsp;&nbsp; for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {</span><br /><span style="background-color: rgb(230,230,250)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ("com.example.MyService".equals(service.service.getClassName())) {</span><br /><span style="background-color: rgb(230,230,250)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return true;</span><br /><span style="background-color: rgb(230,230,250)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br /><span style="background-color: rgb(230,230,250)">&nbsp;&nbsp;&nbsp; }</span><br /><span style="background-color: rgb(230,230,250)">&nbsp;&nbsp;&nbsp; return false;</span><br /><span style="background-color: rgb(230,230,250)">}</span><br /><br />这个方法是可靠的，因为这是由Android系统提供的服务查询办法。<br />所以以来于OnDestroy或者OnXXX方法，甚或是Binders以及静态变量的方法都是不可靠的，因为作为一个开发者，你永远不知道Android系统什么时候会杀掉你的进程来释放内存，那些回调函数很可能根本没机会被调用。<br /><br />另外，关于如果希望手工检查所有后台服务的运行状态，见如何观察和控制正在运行的Android后台服务.</span></p><img src ="http://www.blogjava.net/jjshcc/aggbug/373827.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2012-04-11 17:33 <a href="http://www.blogjava.net/jjshcc/archive/2012/04/11/373827.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Android的线程使用来更新UI----Thread、Handler、Looper、TimerTask等 </title><link>http://www.blogjava.net/jjshcc/archive/2012/04/11/373822.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Wed, 11 Apr 2012 09:04:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2012/04/11/373822.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/373822.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2012/04/11/373822.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/373822.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/373822.html</trackback:ping><description><![CDATA[<p><span style="font-size: 16px"><strong>方法一：(java习惯，在android不推荐使用）</strong></span></p>
<p>刚刚开始接触android线程编程的时候，习惯好像java一样，试图用下面的代码解决问题</p>
<div class="cnblogs_code"><pre><div><span style="color: #0000ff">new</span><span style="color: #000000"> Thread( </span><span style="color: #0000ff">new</span><span style="color: #000000"> Runnable() {     <br />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> run() {     <br />         myView.invalidate();    <br />     }            <br />}).start();</span></div></pre></div>
<p>可以实现功能，刷新UI界面。但是这样是不行的，因为它违背了单线程模型：Android UI操作并不是线程安全的并且这些操作必须在UI线程中执行。</p>
<p><span style="font-size: 16px"><strong>方法二：（Thread+Handler)</strong></span></p>
<p>查阅了文档和apidemo后，发觉常用的方法是利用Handler来实现UI线程的更新的。</p>
<p>Handler来根据接收的消息，处理UI更新。Thread线程发出Handler消息，通知更新UI。</p>
<div class="cnblogs_code"><pre><div><span style="color: #000000">Handler myHandler </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> Handler() {  <br />          </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> handleMessage(Message msg) {   <br />               </span><span style="color: #0000ff">switch</span><span style="color: #000000"> (msg.what) {   <br />                    </span><span style="color: #0000ff">case</span><span style="color: #000000"> TestHandler.GUIUPDATEIDENTIFIER:   <br />                         myBounceView.invalidate();  <br />                         </span><span style="color: #0000ff">break</span><span style="color: #000000">;   <br />               }   <br />               </span><span style="color: #0000ff">super</span><span style="color: #000000">.handleMessage(msg);   <br />          }   <br />     };  </span></div></pre></div>
<div class="cnblogs_code"><pre><div><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> myThread </span><span style="color: #0000ff">implements</span><span style="color: #000000"> Runnable {   <br />          </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> run() {  <br />               </span><span style="color: #0000ff">while</span><span style="color: #000000"> (</span><span style="color: #000000">!</span><span style="color: #000000">Thread.currentThread().isInterrupted()) {    <br />                       <br />                    Message message </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> Message();   <br />                    message.what </span><span style="color: #000000">=</span><span style="color: #000000"> TestHandler.GUIUPDATEIDENTIFIER;   <br />                      <br />                    TestHandler.</span><span style="color: #0000ff">this</span><span style="color: #000000">.myHandler.sendMessage(message);   <br />                    </span><span style="color: #0000ff">try</span><span style="color: #000000"> {   <br />                         Thread.sleep(</span><span style="color: #000000">100</span><span style="color: #000000">);    <br />                    } </span><span style="color: #0000ff">catch</span><span style="color: #000000"> (InterruptedException e) {   <br />                         Thread.currentThread().interrupt();   <br />                    }   <br />               }   <br />          }   <br />     }   </span></div></pre></div>
<p>以上方法demo看:<a href="http://rayleung.javaeye.com/blog/411860">http://rayleung.javaeye.com/blog/411860</a></p>
<p><strong><span style="font-size: 16px">方法三：（java习惯，不推荐）</span></strong></p>
<p>在Android平台中需要反复按周期执行方法可以使用Java上自带的TimerTask类，TimerTask相对于Thread来说对于资源消耗的更低，除了使用Android自带的AlarmManager使用Timer定时器是一种更好的解决方法。 我们需要引入import java.util.Timer; 和 import java.util.TimerTask;</p>
<div class="cnblogs_code"><pre><div><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> JavaTimer </span><span style="color: #0000ff">extends</span><span style="color: #000000"> Activity {  <br />  <br />    Timer timer </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> Timer();  <br />    TimerTask task </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> TimerTask(){   <br />        </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> run() {  <br />            setTitle(</span><span style="color: #000000">"</span><span style="color: #000000">hear me?</span><span style="color: #000000">"</span><span style="color: #000000">);  <br />        }            <br />    };  <br /><br />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> onCreate(Bundle savedInstanceState) {  <br />        </span><span style="color: #0000ff">super</span><span style="color: #000000">.onCreate(savedInstanceState);  <br />        setContentView(R.layout.main);  <br />       <br />         timer.schedule(task, </span><span style="color: #000000">10000</span><span style="color: #000000">);  <br /><br />    }  <br />}  </span></div></pre></div>
<p><span style="font-size: 16px"><strong>方法四：(TimerTask + Handler)</strong></span></p>
<p>实际上这样做是不行的，这跟Android的线程安全有关！应该通过配合Handler来实现timer功能的！</p>
<div class="cnblogs_code"><pre><div><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> TestTimer </span><span style="color: #0000ff">extends</span><span style="color: #000000"> Activity {  <br />  <br />    Timer timer </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> Timer();  <br />    Handler handler </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> Handler(){   <br />        </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> handleMessage(Message msg) {  <br />            </span><span style="color: #0000ff">switch</span><span style="color: #000000"> (msg.what) {      <br />            </span><span style="color: #0000ff">case</span><span style="color: #000000"> </span><span style="color: #000000">1</span><span style="color: #000000">:      <br />                setTitle(</span><span style="color: #000000">"</span><span style="color: #000000">hear me?</span><span style="color: #000000">"</span><span style="color: #000000">);  <br />                </span><span style="color: #0000ff">break</span><span style="color: #000000">;      <br />            }      <br />            </span><span style="color: #0000ff">super</span><span style="color: #000000">.handleMessage(msg);  <br />        }  <br />          <br />    }; &nbsp;</span></div><div><span style="color: #000000"><br />    TimerTask task </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> TimerTask(){    <br />        </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> run() {  <br />            Message message </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> Message();      <br />            message.what </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">1</span><span style="color: #000000">;      <br />            handler.sendMessage(message);    <br />        }            <br />    }; &nbsp;</span></div><div><span style="color: #000000"><br />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> onCreate(Bundle savedInstanceState) {  <br />        </span><span style="color: #0000ff">super</span><span style="color: #000000">.onCreate(savedInstanceState);  <br />        setContentView(R.layout.main);  <br />     &nbsp;</span></div><div><span style="color: #000000">        timer.schedule(task, </span><span style="color: #000000">10000</span><span style="color: #000000">);  <br />    }  <br />}  </span></div></pre></div>
<p><span style="font-size: 16px"><strong>方法五：( Runnable + Handler<span style="line-height: 24px">.</span>postDelayed(runnable,time)&nbsp;)</strong></span></p>
<p>在Android里定时更新 UI，通常使用的是&nbsp;<em>java.util.Timer</em>,&nbsp;<em>java.util.TimerTask</em>, android<em>.os.</em>Handler组合。实际上Handler 自身已经提供了定时的功能。&nbsp;</p>
<div class="cnblogs_code"><pre><div><span style="color: #000000">    </span><span style="color: #0000ff">private</span><span style="color: #000000"> Handler handler </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> Handler();  <br />  <br />    </span><span style="color: #0000ff">private</span><span style="color: #000000"> Runnable myRunnable</span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> Runnable() {    <br />        </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> run() {  <br />             <br />            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (run) {  <br />                handler.postDelayed(</span><span style="color: #0000ff">this</span><span style="color: #000000">, </span><span style="color: #000000">1000</span><span style="color: #000000">);  <br />                count</span><span style="color: #000000">++</span><span style="color: #000000">;  <br />            }  <br />            tvCounter.setText(</span><span style="color: #000000">"</span><span style="color: #000000">Count: </span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">+</span><span style="color: #000000"> count);  <br /><br />        }  <br />    };  </span></div></pre></div>
<p>然后在其他地方调用</p>
<p>handler.post(myRunnable);</p>
<p>handler.post(myRunnable,time);</p>
<p>案例看：<a href="http://shaobin0604.javaeye.com/blog/515820">http://shaobin0604.javaeye.com/blog/515820</a></p>
<p>====================================================================</p>
<p><span style="font-size: 14pt"><strong>知识点总结补充：</strong></span></p>
<p>&nbsp; &nbsp;很多初入Android或Java开发的新手对Thread、Looper、Handler和Message仍然比较迷惑，衍生的有HandlerThread、java.util.concurrent、Task、AsyncTask由于目前市面上的书籍等资料都没有谈到这些问题，今天就这一问题做更系统性的总结。我们创建的Service、Activity以及Broadcast均是一个主线程处理，这里我们可以理解为<strong>UI线程</strong>。但是在操作一些耗时操作时，比如I/O读写的大文件读写，数据库操作以及网络下载需要很长时间，为了不阻塞用户界面，出现ANR的响应提示窗口，这个时候我们可以考虑使用Thread线程来解决。</p>
<p>&nbsp; &nbsp;对于从事过J2ME开发的程序员来说Thread比较简单，直接匿名创建重写run方法，调用start方法执行即可。或者从Runnable接口继承，但对于Android平台来说UI控件都没有设计成为<strong>线程安全类型</strong>，所以需要引入一些同步的机制来使其刷新，这点Google在设计Android时倒是参考了下Win32的消息处理机制。</p>
<p>&nbsp;1. 对于线程中的刷新一个View为基类的界面，可以<span style="color: #ff0000"><strong>使用postInvalidate()方法</strong></span>在线程中来处理，其中还提供了一些重写方法比如postInvalidate(int left,int top,int right,int bottom) 来刷新一个矩形区域，以及延时执行，比如postInvalidateDelayed(long delayMilliseconds)或postInvalidateDelayed(long delayMilliseconds,int left,int top,int right,int bottom) 方法，其中第一个参数为毫秒</p>
<p>&nbsp;2. 当然推荐的方法是通过一个<span style="color: #ff0000"><strong>Handler来处理</strong></span>这些，可以在一个线程的run方法中调用handler对象的 postMessage或sendMessage方法来实现，Android程序内部维护着一个消息队列，会轮训处理这些，如果你是Win32程序员可以很好理解这些消息处理，不过相对于Android来说没有提供 PreTranslateMessage这些干涉内部的方法。</p>
<p>3. Looper又是什么呢? ，其实Android中每一个Thread都跟着一个Looper，Looper可以帮助Thread维护一个消息队列，但是Looper和Handler没有什么关系，我们从开源的代码可以看到Android还提供了一个Thread继承类HanderThread可以帮助我们处理，在HandlerThread对象中可以通过getLooper方法获取一个Looper对象控制句柄，我们可以将其这个Looper对象映射到一个Handler中去来实现一个线程同步机制，Looper对象的执行需要初始化Looper.prepare方法就是昨天我们看到的问题，同时推出时还要释放资源，使用Looper.release方法。</p>
<p>4.Message 在Android是什么呢? 对于Android中Handler可以传递一些内容，通过Bundle对象可以封装String、Integer以及Blob二进制对象，我们通过在线程中<strong>使用Handler对象的sendEmptyMessage或sendMessage方法来传递一个Bundle对象到Handler处理器</strong>。对于Handler类提供了重写方法<strong>handleMessage(Message msg)&nbsp;来判断，通过msg.what来区分每条信息</strong>。将Bundle解包来实现Handler类更新UI线程中的内容实现控件的刷新操作。相关的Handler对象有关消息发送sendXXXX相关方法如下，同时还有postXXXX相关方法，这些和Win32中的道理基本一致，一个为发送后直接返回，一个为处理后才返回 .</p>
<p>5. java.util.concurrent对象分析，对于过去从事Java开发的程序员不会对Concurrent对象感到陌生吧，他是JDK 1.5以后新增的重要特性作为掌上设备，我们不提倡使用该类，考虑到Android为我们已经设计好的Task机制，这里不做过多的赘述，相关原因参考下面的介绍:</p>
<p>6. 在Android中还提供了一种有别于线程的处理方式，就是<span style="color: #ff0000"><strong>Task以及AsyncTask</strong></span>，从开源代码中可以看到是针对Concurrent的封装，开发人员可以方便的处理这些异步任务。</p>  <img src ="http://www.blogjava.net/jjshcc/aggbug/373822.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2012-04-11 17:04 <a href="http://www.blogjava.net/jjshcc/archive/2012/04/11/373822.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>android模拟器模拟定位GPS</title><link>http://www.blogjava.net/jjshcc/archive/2012/04/09/373645.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Mon, 09 Apr 2012 09:10:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2012/04/09/373645.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/373645.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2012/04/09/373645.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/373645.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/373645.html</trackback:ping><description><![CDATA[<span style="font-size: 10.5pt; color: #000000; font-family: 'Arial'; mso-spacerun: 'yes'">在模拟器上获取<span style="font-family: Arial">GPS</span><span style="font-family: 宋体">信息时，使用</span><span style="font-family: Arial">Location&nbsp;loc&nbsp;=&nbsp;LocationManager.getLastKnownLocation("gps");</span><span style="font-family: 宋体">来获取</span><span style="font-family: Arial">location</span><span style="font-family: 宋体">信息，但是往往在调试中</span><span style="font-family: Arial">loc</span><span style="font-family: 宋体">是</span><span style="font-family: Arial">null</span><span style="font-family: 宋体">的，因为首先需要在模拟器中手动添加</span><span style="font-family: Arial">GPS</span><span style="font-family: 宋体">信息，有两种手动添加方法</span></span><span style="font-size: 10.5pt; color: #000000; font-family: 'Arial'; mso-spacerun: 'yes'"><br /></span><span style="font-size: 10.5pt; color: #000000; font-family: 'Arial'; mso-spacerun: 'yes'">1<span style="font-family: 宋体">、在</span><span style="font-family: Arial">eclipse</span><span style="font-family: 宋体">下，</span><span style="font-family: Arial">windows--&gt;open&nbsp;perspective--&gt;DDMS--&gt;Emulator&nbsp;control--&gt;Manual</span><span style="font-family: 宋体">下手动设置经纬度，并按</span><span style="font-family: Arial">send</span><span style="font-family: 宋体">按钮。</span></span><span style="font-size: 10.5pt; color: #000000; font-family: 'Arial'; mso-spacerun: 'yes'"><br /></span><span style="font-size: 10.5pt; color: #000000; font-family: 'Arial'; mso-spacerun: 'yes'">2<span style="font-family: 宋体">、在</span><span style="font-family: Arial">cmd</span><span style="font-family: 宋体">下手动添加信息。</span></span><span style="font-size: 10.5pt; color: #000000; font-family: 'Arial'; mso-spacerun: 'yes'"><br /></span><span style="font-size: 10.5pt; color: #000000; font-family: 'Arial'; mso-spacerun: 'yes'">(1)<span style="font-family: 宋体">首先打开模拟器，然后运行</span><span style="font-family: Arial">cmd</span><span style="font-family: 宋体">，输入</span><span style="font-family: Arial">telnet&nbsp;localhost&nbsp;5554(</span><span style="font-family: 宋体">注：</span><span style="font-family: Arial">5554</span><span style="font-family: 宋体">是模拟器在本机的端口，有可能不一样哈，具体端口号，模拟器左上方有显示的</span><span style="font-family: Arial">)</span><span style="font-family: 宋体">，这样会出现</span></span><span style="font-size: 10.5pt; color: #000000; font-family: 'Arial'; mso-spacerun: 'yes'"><br /></span><span style="font-size: 10.5pt; color: #000000; font-family: 'Arial'; mso-spacerun: 'yes'">Android&nbsp;Console:&nbsp;type&nbsp;'help'&nbsp;for&nbsp;a&nbsp;list&nbsp;of&nbsp;commands</span><span style="font-size: 10.5pt; color: #000000; font-family: 'Arial'; mso-spacerun: 'yes'"><br /></span><span style="font-size: 10.5pt; color: #000000; font-family: 'Arial'; mso-spacerun: 'yes'">OK<span style="font-family: 宋体">的字样。</span></span><span style="font-weight: bold; font-size: 10.5pt; color: #ff0000; font-family: 'Arial'; mso-spacerun: 'yes'"><br /></span><span style="color: #000000"><span style="font-weight: bold; font-size: 10.5pt; font-family: 'Arial'; mso-spacerun: 'yes'">如果是使用<span style="font-family: Arial">WIN7</span><span style="font-family: 宋体">的朋友，控制台可能会提示</span><span style="font-family: Arial">telnet</span><span style="font-family: 宋体">无效什么的，那是因为</span><span style="font-family: Arial">WIN7</span><span style="font-family: 宋体">下默认是不出现</span><span style="font-family: Arial">telnet</span><span style="font-family: 宋体">的，需要手动打开。具体为：</span><span style="font-family: Arial">[1]</span><span style="font-family: 宋体">控制面板</span><span style="font-family: Arial">--&gt;</span><span style="font-family: 宋体">程序</span><span style="font-family: Arial">--&gt;</span><span style="font-family: 宋体">打开或关闭</span><span style="font-family: Arial">Windows</span><span style="font-family: 宋体">功能，然后将</span><span style="font-family: Arial">Telnet</span><span style="font-family: 宋体">服务器和</span><span style="font-family: Arial">Telnet</span><span style="font-family: 宋体">客户端勾选上。</span><span style="font-family: Arial">[2]</span><span style="font-family: 宋体">然后在管理工具</span><span style="font-family: Arial">--&gt;</span><span style="font-family: 宋体">服务中手动启动</span><span style="font-family: Arial">Telnet</span></span><span style="font-size: 10.5pt; font-family: 'Arial'; mso-spacerun: 'yes'"><br /></span></span><span style="font-size: 10.5pt; color: #000000; font-family: 'Arial'; mso-spacerun: 'yes'">(2)<span style="font-family: 宋体">使用</span><span style="font-family: Arial">geo</span><span style="font-family: 宋体">命令模拟发送</span><span style="font-family: Arial">GPS</span><span style="font-family: 宋体">信号：</span></span><span style="font-size: 10.5pt; color: #000000; font-family: 'Arial'; mso-spacerun: 'yes'"><br /></span><span style="font-size: 10.5pt; color: #000000; font-family: 'Arial'; mso-spacerun: 'yes'">geo&nbsp;fix&nbsp;<span style="font-family: 宋体">经度&nbsp;纬度</span></span><span style="font-size: 10.5pt; color: #000000; font-family: 'Arial'; mso-spacerun: 'yes'"><br /></span><span style="font-size: 10.5pt; color: #000000; font-family: 'Arial'; mso-spacerun: 'yes'">(3)<span style="font-family: 宋体">这时就会发现在模拟器的状态栏上多了一个</span><span style="font-family: Arial">GPS</span><span style="font-family: 宋体">的标志</span><span style="font-family: Arial">~</span><span style="font-family: 宋体">再使用</span><span style="font-family: Arial">Location&nbsp;loc&nbsp;=&nbsp;LocationManager.getLastKnownLocation("gps");</span><span style="font-family: 宋体">就能获取到该坐标的位置了</span><span style="font-family: Arial">~~</span></span><img src ="http://www.blogjava.net/jjshcc/aggbug/373645.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2012-04-09 17:10 <a href="http://www.blogjava.net/jjshcc/archive/2012/04/09/373645.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Android 桌面组件</title><link>http://www.blogjava.net/jjshcc/archive/2012/04/07/373553.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Sat, 07 Apr 2012 13:48:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2012/04/07/373553.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/373553.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2012/04/07/373553.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/373553.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/373553.html</trackback:ping><description><![CDATA[下面是本篇的大纲：<br /><br />&nbsp; &nbsp; * 1、AppWidget 框架类<br />&nbsp; &nbsp; * 2、在 Android 如何使用 Widget<br />&nbsp; &nbsp; * 3、AppWidget 框架的主要类介绍<br />&nbsp; &nbsp; * 4、DEMO 讲解 <br /><br /><strong>1、AppWidget 框架类</strong><br /><br />&nbsp; &nbsp; * 1、AppWidgetProvider ：继承自 BroadcastRecevier ， 在AppWidget 应用 update、enable、disable 和 delete 时接收通知。其中，onUpdate、onReceive 是最常用到的方法，它们接收更新通知。<br />&nbsp; &nbsp; * 2、 AppWidgetProvderInfo：描述 AppWidget 的大小、更新频率和初始界面等信息，以XML 文件形式存在于应用的 res/xml/目录下。<br />&nbsp; &nbsp; * 3、AppWidgetManger ：负责管理 AppWidget ，向 AppwidgetProvider 发送通知。<br />&nbsp; &nbsp; * 4、RemoteViews ：一个可以在其他应用进程中运行的类，向 AppWidgetProvider 发送通知。 <br /><br /><strong>2、在 Android 如何使用 Widget</strong><br /><br />&nbsp; &nbsp; * 1、长按主界面<br /><ignore_js_op><img id="aimg_16554" title="1.jpg" style="cursor: pointer" alt="1.jpg" src="http://www.devdiv.com/forum.php?mod=attachment&amp;aid=MTY1NTR8ZWVjODg5ODF8MTMzMzgwNjE2NHwwfDU3Njk4" unselectable="true" status="2" outfunc="null" initialized="true" zoomfile="forum.php?mod=attachment&amp;aid=MTY1NTR8ZWVjODg5ODF8MTMzMzgwNjE2NHwwfDU3Njk4&amp;noupdate=yes&amp;nothumb=yes" file="forum.php?mod=attachment&amp;aid=MTY1NTR8ZWVjODg5ODF8MTMzMzgwNjE2NHwwfDU3Njk4" inpost="1" /> 
<div class="tip tip_4 aimg_tip" id="aimg_16554_menu" style="display: none; z-index: 301; left: 227px; position: absolute; top: 744px" initialized="true" cache="1" fade="false" cover="0" layer="1" mtype="menu" ctrlkey="aimg_16554">
<div class="tip_c xs0">
<div class="y">2011-3-22 23:46:02 上传</div><a title="1.jpg 下载次数:10" href="http://www.devdiv.com/forum.php?mod=attachment&amp;aid=MTY1NTR8ZWVjODg5ODF8MTMzMzgwNjE2NHwwfDU3Njk4&amp;nothumb=yes" target="_blank"><strong>下载附件</strong> <span class="xs0">(41.32 KB)</span></a> </div>
<div class="tip_horn"></div></div></ignore_js_op><br />&nbsp; &nbsp; * 2、之后弹出一个对话框，里面就有android 内置的一些桌面组件<br /><ignore_js_op><img id="aimg_16555" title="appwidget.png" style="cursor: pointer" alt="appwidget.png" src="http://www.devdiv.com/forum.php?mod=attachment&amp;aid=MTY1NTV8NGQ0ODlmNGN8MTMzMzgwNjE2NHwwfDU3Njk4" status="2" zoomfile="forum.php?mod=attachment&amp;aid=MTY1NTV8NGQ0ODlmNGN8MTMzMzgwNjE2NHwwfDU3Njk4&amp;noupdate=yes&amp;nothumb=yes" file="forum.php?mod=attachment&amp;aid=MTY1NTV8NGQ0ODlmNGN8MTMzMzgwNjE2NHwwfDU3Njk4" inpost="1" /> 
<div class="tip tip_4 aimg_tip" id="aimg_16555_menu" style="display: none; position: absolute">
<div class="tip_c xs0">
<div class="y">2011-3-22 23:46:45 上传</div><a title="appwidget.png 下载次数:10" href="http://www.devdiv.com/forum.php?mod=attachment&amp;aid=MTY1NTV8NGQ0ODlmNGN8MTMzMzgwNjE2NHwwfDU3Njk4&amp;nothumb=yes" target="_blank"><strong>下载附件</strong> <span class="xs0">(51.56 KB)</span></a> </div>
<div class="tip_horn"></div></div></ignore_js_op><br /><br /><strong>3、AppWidget 框架的主要类介绍</strong><br /><br />1) AppWidgetManger 类<br /><br />&nbsp; &nbsp; * bindAppWidgetId(int appWidgetId, ComponentName provider)<br />&nbsp; &nbsp;&nbsp; &nbsp;通过给定的ComponentName 绑定appWidgetId<br />&nbsp; &nbsp; * getAppWidgetIds(ComponentName provider)<br />&nbsp; &nbsp;&nbsp; &nbsp;通过给定的ComponentName 获取AppWidgetId<br />&nbsp; &nbsp; * getAppWidgetInfo(int appWidgetId)<br />&nbsp; &nbsp;&nbsp; &nbsp;通过AppWidgetId 获取 AppWidget 信息<br />&nbsp; &nbsp; * getInstalledProviders()<br />&nbsp; &nbsp;&nbsp; &nbsp;返回一个List&lt;AppWidgetProviderInfo&gt;的信息<br />&nbsp; &nbsp; * getInstance(Context context)<br />&nbsp; &nbsp;&nbsp; &nbsp;获取 AppWidgetManger 实例使用的上下文对象<br />&nbsp; &nbsp; * updateAppWidget(int[] appWidgetIds, RemoteViews views)<br />&nbsp; &nbsp;&nbsp; &nbsp;通过appWidgetId 对传进来的 RemoteView 进行修改，并重新刷新AppWidget 组件<br />&nbsp; &nbsp; * updateAppWidget(ComponentName provider, RemoteViews views)<br />&nbsp; &nbsp;&nbsp; &nbsp;通过 ComponentName 对传进来的 RemoeteView 进行修改，并重新刷新AppWidget 组件<br />&nbsp; &nbsp; * updateAppWidget(int appWidgetId, RemoteViews views)<br />&nbsp; &nbsp;&nbsp; &nbsp;通过appWidgetId 对传进来的 RemoteView 进行修改，并重新刷新AppWidget 组件<br /><br />2) 继承自 AppWidgetProvider 可实现的方法为如下：<br /><br />&nbsp; &nbsp; * 1、onDeleted(Context context, int[] appWidgetIds)<br />&nbsp; &nbsp; * 2、onDisabled(Context context)<br />&nbsp; &nbsp; * 3、onEnabled(Context context)<br />&nbsp; &nbsp; * 4、onReceive(Context context, Intent intent)<br />&nbsp; &nbsp;&nbsp; &nbsp;Tip:因为 AppWidgetProvider 是继承自BroadcastReceiver&nbsp;&nbsp;所以可以重写onRecevie 方法，当然必须在后台注册Receiver<br />&nbsp; &nbsp; * 5、onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) <br /><br /><strong>4、Demo讲解</strong><br /><br />下面是我今天做的一个实例，提供给大家练习时做参考，效果如下：在布局中放一个 TextView 做桌面组件，然后设置TextView 的 Clickable="true" 使其有点击的功能，然后我们点击它时改变它的字体，再点击时变回来，详细操作如下流程：<br /><br />&nbsp; &nbsp; * 1、新建AppWidgetProvderInfo<br />&nbsp; &nbsp; * 2、写一个类继承自AppWidgetProvider<br />&nbsp; &nbsp; * 3、后台注册Receiver<br />&nbsp; &nbsp; * 4、使 AppWidget 组件支持点击事件<br />&nbsp; &nbsp; * 5、如何使TextView 在两种文本间来回跳转 <br /><br />问题抛出来了，那么一起解决它吧。<br /><br /><strong>1、新建AppWidgetProvderInfo</strong><br /><br />代码如下： 
<div class="blockcode">
<div id="code0">
<ol><li>&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br /></li><li>&lt;appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"<br /></li><li>&nbsp; &nbsp; android:minWidth="60dp"<br /></li><li>&nbsp; &nbsp; android:minHeight="30dp"<br /></li><li>&nbsp; &nbsp; android:updatePeriodMillis="86400000"<br /></li><li>&nbsp; &nbsp;&nbsp;&nbsp;<br /></li><li>&nbsp; &nbsp; android:initialLayout="@layout/main"&gt;<br /></li><li>&lt;/appwidget-provider&gt;</li></ol></div><em>复制代码</em></div>Tip:上文说过AppWidgetProvderInfo 是在res/xml 的文件形式存在的，看参数不难理解，比较重要的是这里android:initialLayout="@layout/main" 此句为指定桌面组件的布局文件。<br /><br /><strong>2、写一个类继承自AppWidgetProvider</strong><br /><br />主要代码如下： 
<div class="blockcode">
<div id="code1">
<ol><li>public class widgetProvider extends AppWidgetProvider</li></ol></div><em>复制代码</em></div>并重写两个方法 
<div class="blockcode">
<div id="code2">
<ol><li>@Override<br /></li><li>&nbsp; &nbsp; public void onUpdate(Context context, AppWidgetManager appWidgetManager,<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;int[] appWidgetIds) {}<br /></li><li><br /></li><li>@Override<br /></li><li>&nbsp; &nbsp; public void onReceive(Context context, Intent intent) {}</li></ol></div><em>复制代码</em></div>Tip：onUpdate 为组件在桌面上生成时调用，并更新组件UI，onReceiver 为接收广播时调用更新UI，一般这两个方法是比较常用的。<br /><br /><strong>3、后台注册Receiver</strong><br /><br />后台配置文件代码如下： 
<div class="blockcode">
<div id="code3">
<ol><li>&lt;receiver android:name=".widgetProvider"&gt;<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&lt;meta-data android:name="android.appwidget.provider"<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; android:resource="@xml/appwidget_provider"&gt;&lt;/meta-data&gt;<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&lt;intent-filter&gt;<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &lt;action android:name="com.terry.action.widget.click"&gt;&lt;/action&gt;<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt;<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&lt;/intent-filter&gt;<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&lt;/receiver&gt;</li></ol></div><em>复制代码</em></div>Tip:因为是桌面组件，所以暂时不考虑使用Activity 界面，当然你在实现做项目时可能会需要点击时跳转到Activity 应用程序上做操作，典型的案例为Android&nbsp;&nbsp;提供的音乐播放器。上面代码中比较重要的是这一句 &lt;meta-data android:name="android.appwidget.provider"&nbsp;&nbsp;android:resource="@xml/appwidget_provider"&gt;&lt;/meta-data&gt;&nbsp;&nbsp;大意为指定桌面应用程序的AppWidgetProvderInfo&nbsp;&nbsp;文件，使其可作其管理文件。<br /><br /><strong>4、使 AppWidget 组件支持点击事件</strong><br /><br />先看代码： 
<div class="blockcode">
<div id="code4">
<ol><li>public static void updateAppWidget(Context context,<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;AppWidgetManager appWidgeManger, int appWidgetId) {<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;rv = new RemoteViews(context.getPackageName(), R.layout.main);<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Intent intentClick = new Intent(CLICK_NAME_ACTION);<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; intentClick, 0);<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;rv.setOnClickPendingIntent(R.id.TextView01, pendingIntent);<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;appWidgeManger.updateAppWidget(appWidgetId, rv);<br /></li><li>&nbsp; &nbsp; }</li></ol></div><em>复制代码</em></div>此方法为创建组件时 onUpdate 调用的更新UI的方法，代码中使用RemoteView 找到组件的布局文件，同时为其设置广播接收器CLICK_NAME_ACTION并且通过RemoteView 的setOnClickPendingIntent 方法找到我想触发事件的TextView 为其设置广播。接着 
<div class="blockcode">
<div id="code5">
<ol><li>@Override<br /></li><li>&nbsp; &nbsp; public void onReceive(Context context, Intent intent) {<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// TODO Auto-generated method stub<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;super.onReceive(context, intent);<br /></li><li><br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (rv == null) {<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;rv = new RemoteViews(context.getPackageName(), R.layout.main);<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (intent.getAction().equals(CLICK_NAME_ACTION)) {<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if (uitil.isChange) {<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; rv.setTextViewText(R.id.TextView01, context.getResources()<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;.getString(R.string.load));<br /></li><li><br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;} else {<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; rv.setTextViewText(R.id.TextView01, context.getResources()<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;.getString(R.string.change));<br /></li><li><br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Toast.makeText(context, Boolean.toString(uitil.isChange),<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Toast.LENGTH_LONG).show();<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;uitil.isChange = !uitil.isChange;<br /></li><li><br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;AppWidgetManager appWidgetManger = AppWidgetManager<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; .getInstance(context);<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;int[] appIds = appWidgetManger.getAppWidgetIds(new ComponentName(<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; context, widgetProvider.class));<br /></li><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;appWidgetManger.updateAppWidget(appIds, rv);<br /></li><li>&nbsp; &nbsp; }</li></ol></div><em>复制代码</em></div>在onReceiver 中通过判断传进来的广播来触发动作。<br /><br />5、如何使TextView 在两种文本间来回跳转<br /><br />如何 TextView 在来两种状态中来回呢？这也是我比较调试最久的一个难点，问题出在对 AppWidget 的理解不够深入。 如果我的设想没错的话AppWidget 的生命周期应该在每接收一次广播执行一次为一个生命周期结束，也就是说你在重写的 AppWidgetProvider 类里面声明全局变量做状态判断，每次状态改变AppWidgetProvider 再接收第二次广播时即为你重新初始化也就是说桌件为你重新实例化了一次AppWidgetProvider 。今天我因为在里面放了一个boolean 值初始化为true ，观察调试看到每次进入都为TRUE 故你在设置桌面组件时，全局变量把它声明在另外一个实体类用来判断是没问题的，切忌放在本类。代码参考onReceiver方法。<br /><br />效果图如下：<br /><ignore_js_op><img class="zoom" id="aimg_16556" title="fasada.png" alt="fasada.png" src="http://www.devdiv.com/forum.php?mod=attachment&amp;aid=MTY1NTZ8MTVhYjcyYzl8MTMzMzgwNjE2NHwwfDU3Njk4&amp;noupdate=yes" width="218" status="2" zoomfile="forum.php?mod=attachment&amp;aid=MTY1NTZ8MTVhYjcyYzl8MTMzMzgwNjE2NHwwfDU3Njk4&amp;noupdate=yes&amp;nothumb=yes" file="forum.php?mod=attachment&amp;aid=MTY1NTZ8MTVhYjcyYzl8MTMzMzgwNjE2NHwwfDU3Njk4&amp;noupdate=yes" inpost="1" /> 
<div class="tip tip_4 aimg_tip" id="aimg_16556_menu" style="display: none; position: absolute">
<div class="tip_c xs0">
<div class="y">2011-3-22 23:51:58 上传</div><a title="fasada.png 下载次数:10" href="http://www.devdiv.com/forum.php?mod=attachment&amp;aid=MTY1NTZ8MTVhYjcyYzl8MTMzMzgwNjE2NHwwfDU3Njk4&amp;nothumb=yes" target="_blank"><strong>下载附件</strong> <span class="xs0">(10.84 KB)</span></a> </div>
<div class="tip_horn"></div></div></ignore_js_op><br /><br />代码：<br />package com.terry;<br /><br />import android.app.PendingIntent;<br />import android.appwidget.AppWidgetManager;<br />import android.appwidget.AppWidgetProvider;<br />import android.content.ComponentName;<br />import android.content.Context;<br />import android.content.Intent;<br />import android.widget.RemoteViews;<br />import android.widget.Toast;<br /><br />public class widgetProvider extends AppWidgetProvider {<br />&nbsp; &nbsp; private static final String CLICK_NAME_ACTION = "com.terry.action.widget.click";<br /><br />&nbsp; &nbsp; private static RemoteViews rv;<br /><br />&nbsp; &nbsp; @Override<br />&nbsp; &nbsp; public void onUpdate(Context context, AppWidgetManager appWidgetManager,<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;int[] appWidgetIds) {<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// TODO Auto-generated method stub<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;final int N = appWidgetIds.length;<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;for (int i = 0; i &lt; N; i++) {<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;int appWidgetId = appWidgetIds<em>;<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;updateAppWidget(context, appWidgetManager, appWidgetId);<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br />&nbsp; &nbsp; }<br /><br />&nbsp; &nbsp; @Override<br />&nbsp; &nbsp; public void onReceive(Context context, Intent intent) {<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// TODO Auto-generated method stub<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;super.onReceive(context, intent);<br /><br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (rv == null) {<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;rv = new RemoteViews(context.getPackageName(), R.layout.main);<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (intent.getAction().equals(CLICK_NAME_ACTION)) {<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if (uitil.isChange) {<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; rv.setTextViewText(R.id.TextView01, context.getResources()<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;.getString(R.string.load));<br /><br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;} else {<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; rv.setTextViewText(R.id.TextView01, context.getResources()<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;.getString(R.string.change));<br /><br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Toast.makeText(context, Boolean.toString(uitil.isChange),<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Toast.LENGTH_LONG).show();<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;uitil.isChange = !uitil.isChange;<br /><br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;AppWidgetManager appWidgetManger = AppWidgetManager<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; .getInstance(context);<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;int[] appIds = appWidgetManger.getAppWidgetIds(new ComponentName(<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; context, widgetProvider.class));<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;appWidgetManger.updateAppWidget(appIds, rv);<br />&nbsp; &nbsp; }<br /><br />&nbsp; &nbsp; public static void updateAppWidget(Context context,<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;AppWidgetManager appWidgeManger, int appWidgetId) {<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;rv = new RemoteViews(context.getPackageName(), R.layout.main);<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Intent intentClick = new Intent(CLICK_NAME_ACTION);<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; intentClick, 0);<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;rv.setOnClickPendingIntent(R.id.TextView01, pendingIntent);<br />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;appWidgeManger.updateAppWidget(appWidgetId, rv);<br />&nbsp; &nbsp; }<br />}<br /><ignore_js_op><img class="vm" alt="" src="http://www.devdiv.com/static/image/filetype/rar.gif" border="0" /> <span id="attach_16557" style="white-space: nowrap" unselectable="true" outfunc="null" initialized="true"><a href="http://www.devdiv.com/forum.php?mod=attachment&amp;aid=MTY1NTd8NDdjMzczZDB8MTMzMzgwNjE2NHwwfDU3Njk4" target="_blank">widget.rar</a> <em class="xg1">(42.55 KB, 下载次数: 42) </em></span>
<div class="tip tip_4" id="attach_16557_menu" style="display: none; z-index: 301; left: 263px; position: absolute; top: 7293px" initialized="true" cache="1" fade="false" cover="0" layer="1" mtype="menu" ctrlkey="attach_16557">
<div class="tip_c xs0">
<div class="y">2011-3-22 23:52:34 上传</div>下载次数: 42 </div>
<div class="tip_horn"></div></div></ignore_js_op><br /></em><img src ="http://www.blogjava.net/jjshcc/aggbug/373553.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2012-04-07 21:48 <a href="http://www.blogjava.net/jjshcc/archive/2012/04/07/373553.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Android 对话框(Dialog)大全 建立你自己的对话框 </title><link>http://www.blogjava.net/jjshcc/archive/2012/03/12/371743.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Mon, 12 Mar 2012 08:32:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2012/03/12/371743.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/371743.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2012/03/12/371743.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/371743.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/371743.html</trackback:ping><description><![CDATA[Activities提供了一种方便管理的创建、保存、回复的对话框机制，例如&nbsp;<code>onCreateDialog(int)</code>, <code>onPrepareDialog(int, Dialog)</code>, <code>showDialog(int)</code>, <code>dismissDialog(int)等方法，如果使用这些方法的话，Activity将通过<code>getOwnerActivity()方法返回该Activity管理的对话框(dialog).</code></code> 
<p>&nbsp;</p>
<p><code><code>　　<code>onCreateDialog(int):当你使用这个回调函数时，Android系统会有效的设置这个Activity为每个对话框的所有者，从而自动管理每个对话框的状态并挂靠到Activity上。这样，每个对话框继承这个Activity的特定属性。比如，当一个对话框打开时，菜单键显示为这个Activity定义的选项菜单，音量键修改Activity使用的音频流。</code></code></code></p>
<p>&nbsp;</p>
<p><code><code><code>　　<code>showDialog(int):&nbsp;当你想要显示一个对话框时，调用showDialog(int id) 方法并传递一个唯一标识这个对话框的整数。当对话框第一次被请求时，Android从你的Activity中调用onCreateDialog(int id)，你应该在这里初始化这个对话框Dialog。这个回调方法被传以和showDialog(int id)相同的ID。当你创建这个对话框后，在Activity的最后返回这个对象。</code></code></code></code></p>
<p><code></code>&nbsp;</p>
<p><code><code><code><code>　　<code>onPrepareDialog(int, Dialog):在对话框被显示之前，Android还调用了可选的回调函数onPrepareDialog(int id, Dialog). 如果你想在每一次对话框被打开时改变它的任何属性，你可以定义这个方法。这个方法在每次打开对话框时被调用，而onCreateDialog(int) 仅在对话框第一次打开时被调用。如果你不定义onPrepareDialog()，那么这个对话框将保持和上次打开时一样。这个方法也被传递以对话框的ID，和在onCreateDialog()中创建的对话框对象。</code></code></code></code></code></p>
<p><code><code></code></code>&nbsp;</p>
<p><code><code><code><code><code>　　<code>dismissDialog(int):</code></code></code></code></code></code>当你准备关闭对话框时，你可以通过对这个对话框调用dismiss()来消除它。如果需要，你还可以从这个Activity中调用dismissDialog(int id) 方法，这实际上将为你对这个对话框调用dismiss() 方法。 如果你想使用onCreateDialog(int id) 方法来管理你对话框的状态（就如同在前面的章节讨论的那样），然后每次你的对话框消除的时候，这个对话框对象的状态将由该Activity保留。如果你决定不再需要这个对象或者清除该状态是重要的，那么你应该调用removeDialog(int id)。这将删除任何内部对象引用而且如果这个对话框正在显示，它将被消除。</p>
<p>&nbsp;</p>
<p>下面是几种对话框的效果</p>
<p><img style="display: block; margin-left: auto; margin-right: auto" alt="" src="http://pic002.cnblogs.com/images/2010/133128/2010111511252588.png" /></p>
<p style="text-align: center">图1</p>
<p style="text-align: center"><img alt="" src="http://pic002.cnblogs.com/images/2010/133128/2010111511254541.png" /></p>
<p style="text-align: center">图2</p>
<p style="text-align: center"><img alt="" src="http://pic002.cnblogs.com/images/2010/133128/2010111511261716.png" /></p>
<p style="text-align: center">图3</p>
<p style="text-align: center"><img alt="" src="http://pic002.cnblogs.com/images/2010/133128/2010111511263279.png" /></p>
<p style="text-align: center">图4</p>
<p style="text-align: center"><img alt="" src="http://pic002.cnblogs.com/images/2010/133128/2010111511264612.png" /></p>
<p style="text-align: center">图5</p>
<p style="text-align: center"><img alt="" src="http://pic002.cnblogs.com/images/2010/133128/2010111511265817.png" /></p>
<p style="text-align: center">图6</p>
<p style="text-align: center"><img alt="" src="http://pic002.cnblogs.com/images/2010/133128/2010111511271896.png" /></p>
<p style="text-align: center">图7</p>
<p style="text-align: left">　　<span style="font-size: 14pt"><strong>图1效果：</strong></span>该效果是当按返回按钮时弹出一个提示，来确保无误操作，采用常见的对话框样式。</p>
<p style="text-align: left">　　　　　代码：</p>
<p style="text-align: left">　　<span style="font-size: 12pt">创建对话框方法dialog()</span></p>
<p><span style="font-size: 10pt">protected void dialog() {</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;AlertDialog.Builder builder = new Builder(Main.this);</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;builder.setMessage("确认退出吗？");</span></p>
<p><span style="font-size: 10pt">&nbsp;&nbsp;builder.setTitle("提示");</span></p>
<p><span style="font-size: 10pt">&nbsp;&nbsp;builder.setPositiveButton("确认", new OnClickListener() {</span></p>
<p><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;@Override</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;public void onClick(DialogInterface dialog, int which) {</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;dialog.dismiss();</span></p>
<p><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;Main.this.finish();</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;}</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;});</span></p>
<p><span style="font-size: 10pt">&nbsp;&nbsp;builder.setNegativeButton("取消", new OnClickListener() {</span></p>
<p><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;@Override</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;public void onClick(DialogInterface dialog, int which) {</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;dialog.dismiss();</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;}</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;});</span></p>
<p><span style="font-size: 10pt">&nbsp;&nbsp;builder.create().show();</span><br /><span style="font-size: 10pt">&nbsp;}</span></p>
<p>&nbsp;</p>
<p><span style="font-size: 12pt">在onKeyDown(int keyCode, KeyEvent event)方法中调用此方法</span></p>
<p><span style="font-size: 10pt">public boolean onKeyDown(int keyCode, KeyEvent event) {<br />&nbsp;&nbsp;if (keyCode == KeyEvent.KEYCODE_BACK &amp;&amp; event.getRepeatCount() == 0) {<br />&nbsp;&nbsp;&nbsp;dialog();<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;return false;<br />&nbsp;}</span></p>
<p><span style="font-size: 10pt">　　<span style="font-size: 14pt"><strong>图2效果：</strong></span></span>改变了对话框的图表，添加了三个按钮</p>
<p><span style="font-size: 10pt">Dialog dialog = new AlertDialog.Builder(this).setIcon(</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;android.R.drawable.btn_star).setTitle("喜好调查").setMessage(</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"你喜欢李连杰的电影吗？").setPositiveButton("很喜欢",</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new OnClickListener() {</span></p>
<p><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Override</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public void onClick(DialogInterface dialog, int which) {</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// TODO Auto-generated method stub</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Toast.makeText(Main.this, "我很喜欢他的电影。",</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Toast.LENGTH_LONG).show();</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}).setNegativeButton("不喜欢", new OnClickListener() {</span></p>
<p><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;@Override</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;public void onClick(DialogInterface dialog, int which) {</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// TODO Auto-generated method stub</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Toast.makeText(Main.this, "我不喜欢他的电影。", Toast.LENGTH_LONG)</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.show();</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;}</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;}).setNeutralButton("一般", new OnClickListener() {</span></p>
<p><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;@Override</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;public void onClick(DialogInterface dialog, int which) {</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// TODO Auto-generated method stub</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Toast.makeText(Main.this, "谈不上喜欢不喜欢。", Toast.LENGTH_LONG)</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.show();</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;}</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;}).create();</span></p>
<p><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;dialog.show();</span></p>
<p>&nbsp;</p>
<p><span style="font-size: 10pt"><span style="font-size: 14pt"><strong>图3效果：</strong></span></span>信息内容是一个简单的View类型</p>
<p><span style="font-size: 10pt">new AlertDialog.Builder(this).setTitle("请输入").setIcon(</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;android.R.drawable.ic_dialog_info).setView(</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new EditText(this)).setPositiveButton("确定", null)</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setNegativeButton("取消", null).show();</span></p>
<p>&nbsp;</p>
<p><span style="font-size: 10pt"><span style="font-size: 10pt"><span style="font-size: 14pt"><strong>图4效果：</strong></span></span></span>信息内容是一组单选框</p>
<p><span style="font-size: 10pt">new AlertDialog.Builder(this).setTitle("复选框").setMultiChoiceItems(</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new String[] { "Item1", "Item2" }, null, null)</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setPositiveButton("确定", null)</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setNegativeButton("取消", null).show();</span></p>
<p>&nbsp;</p>
<p><span style="font-size: 10pt"><span style="font-size: 10pt"><span style="font-size: 10pt"><span style="font-size: 14pt"><strong>图5效果：</strong></span></span></span></span>信息内容是一组多选框</p>
<p><span style="font-size: 10pt">new AlertDialog.Builder(this).setTitle("单选框").setIcon(</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;android.R.drawable.ic_dialog_info).setSingleChoiceItems(</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new String[] { "Item1", "Item2" }, 0,</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new DialogInterface.OnClickListener() {</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public void onClick(DialogInterface dialog, int which) {</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dialog.dismiss();</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}).setNegativeButton("取消", null).show();</span></p>
<p>&nbsp;</p>
<p><span style="font-size: 10pt"><span style="font-size: 10pt"><span style="font-size: 10pt"><span style="font-size: 10pt"><span style="font-size: 14pt"><strong>图6效果：</strong></span></span></span></span></span>信息内容是一组简单列表项</p>
<p><span style="font-size: 10pt">new AlertDialog.Builder(this).setTitle("列表框").setItems(</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new String[] { "Item1", "Item2" }, null).setNegativeButton(</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"确定", null).show();</span></p>
<p>&nbsp;</p>
<p><span style="font-size: 10pt"><span style="font-size: 10pt"><span style="font-size: 10pt"><span style="font-size: 10pt"><span style="font-size: 10pt"><span style="font-size: 14pt"><strong>图7效果：</strong></span></span></span></span></span>信息内容是一个自定义的布局</span></p>
<p><span style="font-size: 12pt">1.布局文件</span></p>
<p><span style="font-size: 10pt">&lt;?xml version="1.0" encoding="utf-8"?&gt;</span><br /><span style="font-size: 10pt">&lt;LinearLayout xmlns:android="<a href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a>"</span><br /><span style="font-size: 10pt">&nbsp;android:layout_height="wrap_content" android:layout_width="wrap_content"</span><br /><span style="font-size: 10pt">&nbsp;android:background="#ffffffff" android:orientation="horizontal"</span><br /><span style="font-size: 10pt">&nbsp;android:id="@+id/dialog"&gt;</span><br /><span style="font-size: 10pt">&nbsp;&lt;TextView android:layout_height="wrap_content"</span><br /><span style="font-size: 10pt">&nbsp;&nbsp; android:layout_width="wrap_content"</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;android:id="@+id/tvname" android:text="姓名：" /&gt;</span><br /><span style="font-size: 10pt">&nbsp;&lt;EditText android:layout_height="wrap_content"</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;android:layout_width="wrap_content" android:id="@+id/etname" android:minWidth="100dip"/&gt;</span></p>
<p><span style="font-size: 10pt">&lt;/LinearLayout&gt;</span></p>
<p><span style="font-size: 12pt">2.调用代码</span></p>
<p><span style="font-size: 10pt">LayoutInflater inflater = getLayoutInflater();</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;View layout = inflater.inflate(R.layout.dialog,</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(ViewGroup) findViewById(R.id.dialog));</span></p>
<p><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;new AlertDialog.Builder(this).setTitle("自定义布局").setView(layout)</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setPositiveButton("确定", null)</span><br /><span style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setNegativeButton("取消", null).show();</span></p><img src ="http://www.blogjava.net/jjshcc/aggbug/371743.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2012-03-12 16:32 <a href="http://www.blogjava.net/jjshcc/archive/2012/03/12/371743.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>于Activity之间使用广播来解决问题</title><link>http://www.blogjava.net/jjshcc/archive/2012/03/08/371539.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Thu, 08 Mar 2012 09:30:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2012/03/08/371539.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/371539.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2012/03/08/371539.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/371539.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/371539.html</trackback:ping><description><![CDATA[<p>在非主Activity中点击下载按钮时，新建一个线程来下载文件。同时要在非主Activity中定义一个Handler来刷新下载进度。如果界面切到了主Activity界面，当文件下载完成后，非主Activity中的Handler仍会获得信息并处理。我选择在这时发送一个广播：</p>
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">&nbsp;&nbsp;<br /><br />Handler&nbsp;handler&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Handler()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Override<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;handleMessage(Message&nbsp;msg)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(msg.what&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;index</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;msg.getData().getInt(</span><span style="color: #000000">"</span><span style="color: #000000">index</span><span style="color: #000000">"</span><span style="color: #000000">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(index</span><span style="color: #000000">!=</span><span style="color: #000000">0</span><span style="color: #000000">){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">显示进度</span><span style="color: #008000"><br /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(index</span><span style="color: #000000">&gt;=</span><span style="color: #000000">100</span><span style="color: #000000">){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(当前是非主Activity){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">隐藏进度，弹出下载完成提示</span><span style="color: #008000"><br /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span><span style="color: #0000ff">else</span><span style="color: #000000">{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">给主Activity发送一个广播</span><span style="color: #008000"><br /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Intent&nbsp;intent&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Intent(</span><span style="color: #000000">"</span><span style="color: #000000">android.intent.action.MAIN</span><span style="color: #000000">"</span><span style="color: #000000">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sendBroadcast(intent);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />};&nbsp;<br /><br /></span></div>
<p><br /><br />&nbsp;同时，在主Activity中定义一个广播接收器，并处理</p>
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000"><br />BroadcastReceiver&nbsp;mReceiver</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;BroadcastReceiver(){<br />&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;onReceive(Context&nbsp;context,&nbsp;Intent&nbsp;intent)&nbsp;{<br />&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">刷新主Activity界面</span><span style="color: #008000"><br /></span><span style="color: #000000">&nbsp;&nbsp;init();<br />&nbsp;}<br />};<br />IntentFilter&nbsp;intentFilter&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;IntentFilter(</span><span style="color: #000000">"</span><span style="color: #000000">android.intent.action.MAIN</span><span style="color: #000000">"</span><span style="color: #000000">);<br />registerReceiver(mReceiver,&nbsp;intentFilter);&nbsp;&nbsp;<br />&nbsp;<br /></span></div>
<p><br />&nbsp;<br />这样就实现我想要的功能。</p><img src ="http://www.blogjava.net/jjshcc/aggbug/371539.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2012-03-08 17:30 <a href="http://www.blogjava.net/jjshcc/archive/2012/03/08/371539.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>BaseExpandableListAdapter的用法</title><link>http://www.blogjava.net/jjshcc/archive/2012/02/29/371030.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Wed, 29 Feb 2012 11:16:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2012/02/29/371030.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/371030.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2012/02/29/371030.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/371030.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/371030.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->&lt;?xml&nbsp;version="1.0"&nbsp;encoding="utf-8"?&gt;&lt;LinearLayout&nbsp;xmlns:android="htt...&nbsp;&nbsp;<a href='http://www.blogjava.net/jjshcc/archive/2012/02/29/371030.html'>阅读全文</a><img src ="http://www.blogjava.net/jjshcc/aggbug/371030.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2012-02-29 19:16 <a href="http://www.blogjava.net/jjshcc/archive/2012/02/29/371030.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Android中Activity和Intent之间的联系 </title><link>http://www.blogjava.net/jjshcc/archive/2012/02/29/371020.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Wed, 29 Feb 2012 09:29:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2012/02/29/371020.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/371020.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2012/02/29/371020.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/371020.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/371020.html</trackback:ping><description><![CDATA[<div id="cnblogs_post_body">
<p>Intent用法实例</p>
<p>1.无参数Activity跳转</p>
<p>Intent it = new Intent(Activity.Main.this, Activity2.class);<br />startActivity(it);&nbsp;&nbsp;&nbsp; </p>
<p>2.向下一个Activity传递数据（使用Bundle和Intent.putExtras）</p>
<p>Intent it = new Intent(Activity.Main.this, Activity2.class);<br />Bundle bundle=new Bundle();<br />bundle.putString("name", "This is from MainActivity!");<br />it.putExtras(bundle);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // it.putExtra(&#8220;test&#8221;, "shuju&#8221;);<br />startActivity(it);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // startActivityForResult(it,REQUEST_CODE); </p>
<p>对于数据的获取可以采用：</p>
<p>Bundle bundle=getIntent().getExtras();<br />String name=bundle.getString("name"); </p>
<p>3.向上一个Activity返回结果（使用setResult，针对startActivityForResult(it,REQUEST_CODE)启动的Activity）</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Intent intent=getIntent();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Bundle bundle2=new Bundle();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bundle2.putString("name", "This is from ShowMsg!");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; intent.putExtras(bundle2);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setResult(RESULT_OK, intent);<br />4.回调上一个Activity的结果处理函数（onActivityResult）<br />@Override<br />&nbsp;&nbsp;&nbsp; protected void onActivityResult(int requestCode, int resultCode, Intent data) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // TODO Auto-generated method stub<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; super.onActivityResult(requestCode, resultCode, data);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (requestCode==REQUEST_CODE){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(resultCode==RESULT_CANCELED)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setTitle("cancle");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if (resultCode==RESULT_OK) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String temp=null;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Bundle bundle=data.getExtras();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(bundle!=null)&nbsp;&nbsp; temp=bundle.getString("name");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setTitle(temp);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }</p></div> <img src ="http://www.blogjava.net/jjshcc/aggbug/371020.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2012-02-29 17:29 <a href="http://www.blogjava.net/jjshcc/archive/2012/02/29/371020.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Android中gravity与layout_gravity的区别 </title><link>http://www.blogjava.net/jjshcc/archive/2012/02/29/371017.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Wed, 29 Feb 2012 09:16:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2012/02/29/371017.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/371017.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2012/02/29/371017.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/371017.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/371017.html</trackback:ping><description><![CDATA[LinearLayout有两个非常相似的属性：android:gravity与android:layout_gravity。他们的区别在于：android:gravity用于设置View组件的对齐方式，而android:layout_gravity用于设置Container组件的对齐方式。<br />
<p>举个例子，我们可以通过设置android:gravity="center"来让EditText中的文字在EditText组件中居中显示；同时我们设置EditText的android:layout_gravity="right"来让EditText组件在LinearLayout中居中显示。来实践以下：</p><br />
<p>正如我们所看到的，在EditText中，其中的文字已经居中显示了，而EditText组件自己也对齐到了LinearLayout的右侧。<br /><br /><img src="http://hiphotos.baidu.com/xiechengfa/pic/item/8c90b8e8fbc61a95d539c913.jpg" border="0"  alt="" /></p>
<p>&lt;LinearLayout <br />&nbsp;&nbsp;&nbsp; xmlns:android="<a>http://schemas.android.com/apk/res/android</a>" <br />&nbsp;&nbsp;&nbsp; android:orientation="vertical" <br />&nbsp;&nbsp;&nbsp; android:layout_width="fill_parent" <br />&nbsp;&nbsp;&nbsp; android:layout_height="fill_parent"&gt; <br />&nbsp;&nbsp;&nbsp; &lt;EditText <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; android:layout_width="wrap_content" <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; android:gravity="center" <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; android:layout_height="wrap_content" <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; android:text="one" <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; android:layout_gravity="right"/&gt; <br />&lt;/LinearLayout&gt;<br /><br /></p> <img src ="http://www.blogjava.net/jjshcc/aggbug/371017.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2012-02-29 17:16 <a href="http://www.blogjava.net/jjshcc/archive/2012/02/29/371017.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Sample code to use  Activity and ListView</title><link>http://www.blogjava.net/jjshcc/archive/2012/02/29/371012.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Wed, 29 Feb 2012 08:41:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2012/02/29/371012.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/371012.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2012/02/29/371012.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/371012.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/371012.html</trackback:ping><description><![CDATA[<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /><span style="color: #0000ff">package</span><span style="color: #000000">&nbsp;www.puyufanyi.com;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;java.util.ArrayList;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;java.util.HashMap;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;java.util.List;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;java.util.Map;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;www.puyufanyi.com.test.Word;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;android.app.Activity;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;android.os.Bundle;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;android.view.View;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;android.widget.AdapterView;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;android.widget.AdapterView.OnItemClickListener;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;android.widget.ListView;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;android.widget.SimpleAdapter;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;android.widget.Toast;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;android.widget.TextView;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /><img id="Codehighlighter1_507_1989_Open_Image" onclick="this.style.display='none'; Codehighlighter1_507_1989_Open_Text.style.display='none'; Codehighlighter1_507_1989_Closed_Image.style.display='inline'; Codehighlighter1_507_1989_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_507_1989_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_507_1989_Closed_Text.style.display='none'; Codehighlighter1_507_1989_Open_Image.style.display='inline'; Codehighlighter1_507_1989_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;UIActivity&nbsp;</span><span style="color: #0000ff">extends</span><span style="color: #000000">&nbsp;Activity</span><span id="Codehighlighter1_507_1989_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_507_1989_Open_Text"><span style="color: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">private</span><span style="color: #000000">&nbsp;ArrayList</span><span style="color: #000000">&lt;</span><span style="color: #000000">Word</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;words&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;ArrayList</span><span style="color: #000000">&lt;</span><span style="color: #000000">Word</span><span style="color: #000000">&gt;</span><span style="color: #000000">();<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;@Override<br /><img id="Codehighlighter1_627_1987_Open_Image" onclick="this.style.display='none'; Codehighlighter1_627_1987_Open_Text.style.display='none'; Codehighlighter1_627_1987_Closed_Image.style.display='inline'; Codehighlighter1_627_1987_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_627_1987_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_627_1987_Closed_Text.style.display='none'; Codehighlighter1_627_1987_Open_Image.style.display='inline'; Codehighlighter1_627_1987_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;onCreate(Bundle&nbsp;savedInstanceState)&nbsp;</span><span id="Codehighlighter1_627_1987_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_627_1987_Open_Text"><span style="color: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">super</span><span style="color: #000000">.onCreate(savedInstanceState);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setContentView(R.layout.main);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ListView&nbsp;lv</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(ListView)findViewById(R.id.wordlist);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Word&nbsp;word1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Word(</span><span style="color: #000000">"</span><span style="color: #000000">index1</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">result1</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Word&nbsp;word2&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Word(</span><span style="color: #000000">"</span><span style="color: #000000">index2</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">result2</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Word&nbsp;word3&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Word(</span><span style="color: #000000">"</span><span style="color: #000000">index3</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">result3</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Word&nbsp;word4&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Word(</span><span style="color: #000000">"</span><span style="color: #000000">index4</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">result4</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Word&nbsp;word5&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Word(</span><span style="color: #000000">"</span><span style="color: #000000">index5</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">result5</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.words.add(word1);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.words.add(word2);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.words.add(word3);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.words.add(word4);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.words.add(word5);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List</span><span style="color: #000000">&lt;</span><span style="color: #000000">Map</span><span style="color: #000000">&lt;</span><span style="color: #000000">String,&nbsp;Object</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;listItems&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;ArrayList</span><span style="color: #000000">&lt;</span><span style="color: #000000">Map</span><span style="color: #000000">&lt;</span><span style="color: #000000">String,&nbsp;Object</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">();<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img id="Codehighlighter1_1235_1436_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1235_1436_Open_Text.style.display='none'; Codehighlighter1_1235_1436_Closed_Image.style.display='inline'; Codehighlighter1_1235_1436_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_1235_1436_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1235_1436_Closed_Text.style.display='none'; Codehighlighter1_1235_1436_Open_Image.style.display='inline'; Codehighlighter1_1235_1436_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;words.size();&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)&nbsp;</span><span id="Codehighlighter1_1235_1436_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1235_1436_Open_Text"><span style="color: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Map</span><span style="color: #000000">&lt;</span><span style="color: #000000">String,&nbsp;Object</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;listItem&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;HashMap</span><span style="color: #000000">&lt;</span><span style="color: #000000">String,&nbsp;Object</span><span style="color: #000000">&gt;</span><span style="color: #000000">();<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;listItem.put(</span><span style="color: #000000">"</span><span style="color: #000000">Index</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;words.get(i).getIndex());<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;listItem.put(</span><span style="color: #000000">"</span><span style="color: #000000">Result</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;words.get(i).getResult());<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;listItems.add(listItem);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SimpleAdapter&nbsp;simpleAdapter&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;SimpleAdapter(<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">,&nbsp;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;listItems,&nbsp;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R.layout.words,<br /><img id="Codehighlighter1_1552_1569_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1552_1569_Open_Text.style.display='none'; Codehighlighter1_1552_1569_Closed_Image.style.display='inline'; Codehighlighter1_1552_1569_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_1552_1569_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1552_1569_Closed_Text.style.display='none'; Codehighlighter1_1552_1569_Open_Image.style.display='inline'; Codehighlighter1_1552_1569_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;String[]</span><span id="Codehighlighter1_1552_1569_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1552_1569_Open_Text"><span style="color: #000000">{</span><span style="color: #000000">"</span><span style="color: #000000">Index</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">"</span><span style="color: #000000">Result</span><span style="color: #000000">"</span><span style="color: #000000">}</span></span><span style="color: #000000">,<br /><img id="Codehighlighter1_1585_1608_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1585_1608_Open_Text.style.display='none'; Codehighlighter1_1585_1608_Closed_Image.style.display='inline'; Codehighlighter1_1585_1608_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_1585_1608_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1585_1608_Closed_Text.style.display='none'; Codehighlighter1_1585_1608_Open_Image.style.display='inline'; Codehighlighter1_1585_1608_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">[]</span><span id="Codehighlighter1_1585_1608_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1585_1608_Open_Text"><span style="color: #000000">{R.id.index,R.id.result}</span></span><span style="color: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lv.setAdapter(simpleAdapter);<br /><img id="Codehighlighter1_1701_1973_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1701_1973_Open_Text.style.display='none'; Codehighlighter1_1701_1973_Closed_Image.style.display='inline'; Codehighlighter1_1701_1973_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_1701_1973_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1701_1973_Closed_Text.style.display='none'; Codehighlighter1_1701_1973_Open_Image.style.display='inline'; Codehighlighter1_1701_1973_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lv.setOnItemClickListener(</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;OnItemClickListener()&nbsp;</span><span id="Codehighlighter1_1701_1973_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1701_1973_Open_Text"><span style="color: #000000">{<br /><img id="Codehighlighter1_1786_1967_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1786_1967_Open_Text.style.display='none'; Codehighlighter1_1786_1967_Closed_Image.style.display='inline'; Codehighlighter1_1786_1967_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_1786_1967_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1786_1967_Closed_Text.style.display='none'; Codehighlighter1_1786_1967_Open_Image.style.display='inline'; Codehighlighter1_1786_1967_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;onItemClick(AdapterView</span><span style="color: #000000">&lt;?&gt;</span><span style="color: #000000">&nbsp;parent,&nbsp;View&nbsp;view,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;position,&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;id)&nbsp;</span><span id="Codehighlighter1_1786_1967_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1786_1967_Open_Text"><span style="color: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;&nbsp;indexValue&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;((TextView)view.findViewById(R.id.index)).getText().toString();<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Toast.makeText(getApplicationContext(),&nbsp;indexValue,&nbsp;Toast.LENGTH_SHORT).show();&nbsp;&nbsp;&nbsp;&nbsp;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000">&nbsp;&nbsp;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span></div><br /><strong>main.xml<br /></strong>
<p>&lt;?xml version="1.0" encoding="utf-8"?&gt;<br />&lt;LinearLayout xmlns:android="<a href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a>"<br />&nbsp;&nbsp;&nbsp; android:layout_width="fill_parent"<br />&nbsp;&nbsp;&nbsp; android:layout_height="fill_parent"<br />&nbsp;&nbsp;&nbsp; android:orientation="vertical" &gt;</p>
<p>&nbsp;&nbsp;&nbsp; &lt;!-- ListView (words) --&gt;</p>
<p>&nbsp;&nbsp;&nbsp; &lt;ListView<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; android:id="@+id/wordlist"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; android:layout_width="wrap_content"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; android:layout_height="wrap_content" &gt;<br />&nbsp;&nbsp;&nbsp; &lt;/ListView&gt;</p>
<p>&lt;/LinearLayout&gt;</p><strong>words.xml<br /></strong>
<p>&lt;?xml version="1.0" encoding="utf-8"?&gt;<br />&lt;LinearLayout xmlns:android="<a href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a>"<br />&nbsp;&nbsp;&nbsp; android:layout_width="match_parent"<br />&nbsp;&nbsp;&nbsp; android:layout_height="match_parent"<br />&nbsp;&nbsp;&nbsp; android:orientation="horizontal" &gt;</p>
<p>&nbsp;&nbsp;&nbsp; &lt;TextView<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; android:id="@+id/index"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; android:layout_width="wrap_content"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; android:layout_height="wrap_content"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; android:paddingLeft="10dp" /&gt;</p>
<p>&nbsp;&nbsp;&nbsp; &lt;TextView<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; android:id="@+id/result"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; android:layout_width="wrap_content"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; android:layout_height="wrap_content"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; android:paddingLeft="10dp" /&gt;</p>
<p>&lt;/LinearLayout&gt;</p><br /><br /><br /><br /><br /><br /><br /><img src ="http://www.blogjava.net/jjshcc/aggbug/371012.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2012-02-29 16:41 <a href="http://www.blogjava.net/jjshcc/archive/2012/02/29/371012.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Sample code for ListActivity</title><link>http://www.blogjava.net/jjshcc/archive/2012/02/29/371004.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Wed, 29 Feb 2012 07:36:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2012/02/29/371004.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/371004.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2012/02/29/371004.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/371004.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/371004.html</trackback:ping><description><![CDATA[<div>
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff">package</span><span style="color: #000000">&nbsp;www.puyufanyi.com;<br /><br /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;java.util.ArrayList;<br /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;java.util.HashMap;<br /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;java.util.List;<br /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;java.util.Map;<br /><br /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;www.puyufanyi.com.test.Word;<br /><br /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;android.app.ListActivity;<br /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;android.os.Bundle;<br /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;android.view.View;<br /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;android.widget.AdapterView;<br /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;android.widget.AdapterView.OnItemClickListener;<br /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;android.widget.ListView;<br /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;android.widget.SimpleAdapter;<br /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;android.widget.Toast;<br /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;android.widget.TextView;<br /><br /></span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;UIActivity&nbsp;</span><span style="color: #0000ff">extends</span><span style="color: #000000">&nbsp;ListActivity&nbsp;{<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">private</span><span style="color: #000000">&nbsp;ArrayList</span><span style="color: #000000">&lt;</span><span style="color: #000000">Word</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;words&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;ArrayList</span><span style="color: #000000">&lt;</span><span style="color: #000000">Word</span><span style="color: #000000">&gt;</span><span style="color: #000000">();<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;@Override<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;onCreate(Bundle&nbsp;savedInstanceState)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">super</span><span style="color: #000000">.onCreate(savedInstanceState);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setContentView(R.layout.main);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Word&nbsp;word1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Word(</span><span style="color: #000000">"</span><span style="color: #000000">index1</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">result1</span><span style="color: #000000">"</span><span style="color: #000000">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Word&nbsp;word2&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Word(</span><span style="color: #000000">"</span><span style="color: #000000">index2</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">result2</span><span style="color: #000000">"</span><span style="color: #000000">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Word&nbsp;word3&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Word(</span><span style="color: #000000">"</span><span style="color: #000000">index3</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">result3</span><span style="color: #000000">"</span><span style="color: #000000">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Word&nbsp;word4&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Word(</span><span style="color: #000000">"</span><span style="color: #000000">index4</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">result4</span><span style="color: #000000">"</span><span style="color: #000000">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Word&nbsp;word5&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Word(</span><span style="color: #000000">"</span><span style="color: #000000">index5</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">result5</span><span style="color: #000000">"</span><span style="color: #000000">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.words.add(word1);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.words.add(word2);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.words.add(word3);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.words.add(word4);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.words.add(word5);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List</span><span style="color: #000000">&lt;</span><span style="color: #000000">Map</span><span style="color: #000000">&lt;</span><span style="color: #000000">String,&nbsp;Object</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;listItems&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;ArrayList</span><span style="color: #000000">&lt;</span><span style="color: #000000">Map</span><span style="color: #000000">&lt;</span><span style="color: #000000">String,&nbsp;Object</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">();<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;words.size();&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Map</span><span style="color: #000000">&lt;</span><span style="color: #000000">String,&nbsp;Object</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;listItem&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;HashMap</span><span style="color: #000000">&lt;</span><span style="color: #000000">String,&nbsp;Object</span><span style="color: #000000">&gt;</span><span style="color: #000000">();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;listItem.put(</span><span style="color: #000000">"</span><span style="color: #000000">Index</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;words.get(i).getIndex());<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;listItem.put(</span><span style="color: #000000">"</span><span style="color: #000000">Result</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;words.get(i).getResult());<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;listItems.add(listItem);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SimpleAdapter&nbsp;simpleAdapter&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;SimpleAdapter(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;listItems,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R.layout.main,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;String[]{</span><span style="color: #000000">"</span><span style="color: #000000">Index</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">"</span><span style="color: #000000">Result</span><span style="color: #000000">"</span><span style="color: #000000">},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">[]{R.id.index,R.id.result}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setListAdapter(simpleAdapter);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ListView&nbsp;lv&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;getListView();&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lv.setTextFilterEnabled(</span><span style="color: #0000ff">true</span><span style="color: #000000">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lv.setOnItemClickListener(</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;OnItemClickListener()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;onItemClick(AdapterView</span><span style="color: #000000">&lt;?&gt;</span><span style="color: #000000">&nbsp;parent,&nbsp;View&nbsp;view,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;position,&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;id)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;&nbsp;indexValue&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;((TextView)view.findViewById(R.id.index)).getText().toString();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Toast.makeText(getApplicationContext(),&nbsp;indexValue,&nbsp;Toast.LENGTH_SHORT).show();&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />}</span></div></div>   <img src ="http://www.blogjava.net/jjshcc/aggbug/371004.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2012-02-29 15:36 <a href="http://www.blogjava.net/jjshcc/archive/2012/02/29/371004.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Android 自定义Button按钮显示样式（正常、按下、获取焦点）</title><link>http://www.blogjava.net/jjshcc/archive/2012/02/27/370864.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Mon, 27 Feb 2012 10:04:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2012/02/27/370864.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/370864.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2012/02/27/370864.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/370864.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/370864.html</trackback:ping><description><![CDATA[<p>首先写一个定义Button样式的XML文件：<br />新建Android XML文件，类型选Drawable,根结点选selector,文件名就buton_style吧。<br />程序自动给我们刚刚建的文件里加了selector结点，我们只需要在selector结点里写上三种状态时显示的背景图片（按下、获取焦点，正常）。<br />代码如下：<br /><span id="more-343"></span></p>
<div class="wp_syntax">
<table>
<tbody>
<tr>
<td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td>
<td class="code"><pre class="xml" style="font-family: monospace"><span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;?xml</span> <span style="color: #000066">version</span>=<span style="color: #ff0000">"1.0"</span> <span style="color: #000066">encoding</span>=<span style="color: #ff0000">"utf-8"</span><span style="font-weight: bold; color: #000000">?&gt;</span></span>
<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;selector</span> <span style="color: #000066">xmlns:android</span>=<span style="color: #ff0000">"http://schemas.android.com/apk/res/android"</span><span style="font-weight: bold; color: #000000">&gt;</span></span>
	<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;item</span> <span style="color: #000066">android:state_pressed</span>=<span style="color: #ff0000">"true"</span> <span style="color: #000066">android:drawable</span>=<span style="color: #ff0000">"@drawable/play_press"</span> <span style="font-weight: bold; color: #000000">/&gt;</span></span>
	<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;item</span> <span style="color: #000066">android:state_focused</span>=<span style="color: #ff0000">"true"</span> <span style="color: #000066">android:drawable</span>=<span style="color: #ff0000">"@drawable/play_press"</span> <span style="font-weight: bold; color: #000000">/&gt;</span></span>
	<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;item</span> <span style="color: #000066">android:drawable</span>=<span style="color: #ff0000">"@drawable/play"</span> <span style="font-weight: bold; color: #000000">/&gt;</span></span>
<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;/selector<span style="font-weight: bold; color: #000000">&gt;</span></span></span></pre></td></tr></tbody></table></div>
<p>我这里获取焦点跟点击时显示的是同一张图片，必须严格照上面的顺序写，不可倒。<br />接下来只要在布局时写Button控件时应用到Button的Background属性即可。</p>
<div class="wp_syntax">
<table>
<tbody>
<tr>
<td class="line_numbers"><pre>1
2
3
4
</pre></td>
<td class="code"><pre class="xml" style="font-family: monospace"><span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;Button</span> <span style="color: #000066">android:id</span>=<span style="color: #ff0000">"@+id/button1"</span></span>
<span style="color: #009900">	<span style="color: #000066">android:layout_width</span>=<span style="color: #ff0000">"wrap_content"</span> <span style="color: #000066">android:layout_height</span>=<span style="color: #ff0000">"wrap_content"</span></span>
<span style="color: #009900">	<span style="color: #000066">android:background</span>=<span style="color: #ff0000">"@drawable/button_style"</span></span>
<span style="color: #009900"><span style="font-weight: bold; color: #000000">&gt;</span><span style="font-weight: bold; color: #000000">&lt;/Button<span style="font-weight: bold; color: #000000">&gt;</span></span></span></pre></td></tr></tbody></table></div>
<p>最终效果图：<br /><a href="http://www.pocketdigi.com/wp-content/uploads/2011/06/button_style.jpg"><img class="alignnone size-full wp-image-345" title="button_style" height="447" alt="" src="http://www.pocketdigi.com/wp-content/uploads/2011/06/button_style.jpg" width="236" /></a><br />点击时会变。<br />源代码下载：<br /><a class="downloadlink" title=" downloaded 313 times" href="http://www.pocketdigi.com/wp-content/plugins/download-monitor/download.php?id=19">Button_style (313)</a><br />再加上一种自定义样式方法，上面的是用图片，其实我们可以直接通过定义xml文件来实现不同的样式:<br />在上面的源代码基础上，只需要修改button_style文件,同样三种状态分开定义：</p>
<div class="wp_syntax">
<table>
<tbody>
<tr>
<td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre></td>
<td class="code"><pre class="xml" style="font-family: monospace"><span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;?xml</span> <span style="color: #000066">version</span>=<span style="color: #ff0000">"1.0"</span> <span style="color: #000066">encoding</span>=<span style="color: #ff0000">"utf-8"</span><span style="font-weight: bold; color: #000000">?&gt;</span></span>
<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;selector</span> <span style="color: #000066">xmlns:android</span>=<span style="color: #ff0000">"http://schemas.android.com/apk/res/android"</span><span style="font-weight: bold; color: #000000">&gt;</span></span>
	<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;item</span> <span style="color: #000066">android:state_pressed</span>=<span style="color: #ff0000">"true"</span><span style="font-weight: bold; color: #000000">&gt;</span></span>
		<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;shape<span style="font-weight: bold; color: #000000">&gt;</span></span></span>
			<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;gradient</span> <span style="color: #000066">android:startColor</span>=<span style="color: #ff0000">"#0d76e1"</span> <span style="color: #000066">android:endColor</span>=<span style="color: #ff0000">"#0d76e1"</span></span>
<span style="color: #009900">				<span style="color: #000066">android:angle</span>=<span style="color: #ff0000">"270"</span> <span style="font-weight: bold; color: #000000">/&gt;</span></span>
			<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;stroke</span> <span style="color: #000066">android:width</span>=<span style="color: #ff0000">"1dip"</span> <span style="color: #000066">android:color</span>=<span style="color: #ff0000">"#f403c9"</span> <span style="font-weight: bold; color: #000000">/&gt;</span></span>
			<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;corners</span> <span style="color: #000066">android:radius</span>=<span style="color: #ff0000">"2dp"</span> <span style="font-weight: bold; color: #000000">/&gt;</span></span>
			<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;padding</span> <span style="color: #000066">android:left</span>=<span style="color: #ff0000">"10dp"</span> <span style="color: #000066">android:top</span>=<span style="color: #ff0000">"10dp"</span></span>
<span style="color: #009900">				<span style="color: #000066">android:right</span>=<span style="color: #ff0000">"10dp"</span> <span style="color: #000066">android:bottom</span>=<span style="color: #ff0000">"10dp"</span> <span style="font-weight: bold; color: #000000">/&gt;</span></span>
		<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;/shape<span style="font-weight: bold; color: #000000">&gt;</span></span></span>
	<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;/item<span style="font-weight: bold; color: #000000">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;item</span> <span style="color: #000066">android:state_focused</span>=<span style="color: #ff0000">"true"</span><span style="font-weight: bold; color: #000000">&gt;</span></span>
		<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;shape<span style="font-weight: bold; color: #000000">&gt;</span></span></span>
			<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;gradient</span> <span style="color: #000066">android:startColor</span>=<span style="color: #ff0000">"#ffc2b7"</span> <span style="color: #000066">android:endColor</span>=<span style="color: #ff0000">"#ffc2b7"</span></span>
<span style="color: #009900">				<span style="color: #000066">android:angle</span>=<span style="color: #ff0000">"270"</span> <span style="font-weight: bold; color: #000000">/&gt;</span></span>
			<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;stroke</span> <span style="color: #000066">android:width</span>=<span style="color: #ff0000">"1dip"</span> <span style="color: #000066">android:color</span>=<span style="color: #ff0000">"#f403c9"</span> <span style="font-weight: bold; color: #000000">/&gt;</span></span>
			<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;corners</span> <span style="color: #000066">android:radius</span>=<span style="color: #ff0000">"2dp"</span> <span style="font-weight: bold; color: #000000">/&gt;</span></span>
			<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;padding</span> <span style="color: #000066">android:left</span>=<span style="color: #ff0000">"10dp"</span> <span style="color: #000066">android:top</span>=<span style="color: #ff0000">"10dp"</span></span>
<span style="color: #009900">				<span style="color: #000066">android:right</span>=<span style="color: #ff0000">"10dp"</span> <span style="color: #000066">android:bottom</span>=<span style="color: #ff0000">"10dp"</span> <span style="font-weight: bold; color: #000000">/&gt;</span></span>
		<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;/shape<span style="font-weight: bold; color: #000000">&gt;</span></span></span>
	<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;/item<span style="font-weight: bold; color: #000000">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;item<span style="font-weight: bold; color: #000000">&gt;</span></span></span>
		<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;shape<span style="font-weight: bold; color: #000000">&gt;</span></span></span>
			<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;gradient</span> <span style="color: #000066">android:startColor</span>=<span style="color: #ff0000">"#000000"</span> <span style="color: #000066">android:endColor</span>=<span style="color: #ff0000">"#ffffff"</span></span>
<span style="color: #009900">				<span style="color: #000066">android:angle</span>=<span style="color: #ff0000">"180"</span> <span style="font-weight: bold; color: #000000">/&gt;</span></span>
			<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;stroke</span> <span style="color: #000066">android:width</span>=<span style="color: #ff0000">"1dip"</span> <span style="color: #000066">android:color</span>=<span style="color: #ff0000">"#f403c9"</span> <span style="font-weight: bold; color: #000000">/&gt;</span></span>
			<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;corners</span> <span style="color: #000066">android:radius</span>=<span style="color: #ff0000">"5dip"</span> <span style="font-weight: bold; color: #000000">/&gt;</span></span>
			<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;padding</span> <span style="color: #000066">android:left</span>=<span style="color: #ff0000">"10dp"</span> <span style="color: #000066">android:top</span>=<span style="color: #ff0000">"10dp"</span></span>
<span style="color: #009900">				<span style="color: #000066">android:right</span>=<span style="color: #ff0000">"10dp"</span> <span style="color: #000066">android:bottom</span>=<span style="color: #ff0000">"10dp"</span> <span style="font-weight: bold; color: #000000">/&gt;</span></span>
		<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;/shape<span style="font-weight: bold; color: #000000">&gt;</span></span></span>
	<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;/item<span style="font-weight: bold; color: #000000">&gt;</span></span></span>
<span style="color: #009900"><span style="font-weight: bold; color: #000000">&lt;/selector<span style="font-weight: bold; color: #000000">&gt;</span></span></span></pre></td></tr></tbody></table></div>
<p>gradient 主体渐变 startColor开始颜色，endColor结束颜色 ，angle开始渐变的角度（值只能为90的倍数，0时为左到右渐变，90时为下到上渐变，依次逆时针类推）<br />stroke 边框 width 边框宽度，color 边框颜色<br />corners 圆角 radius 半径，0为直角<br />padding text值的相对位置</p><img src ="http://www.blogjava.net/jjshcc/aggbug/370864.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2012-02-27 18:04 <a href="http://www.blogjava.net/jjshcc/archive/2012/02/27/370864.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>