
{"id":252,"date":"2016-03-18T09:15:52","date_gmt":"2016-03-18T01:15:52","guid":{"rendered":"http:\/\/www.jiandaima.com\/blog\/?p=252"},"modified":"2016-05-07T12:50:33","modified_gmt":"2016-05-07T04:50:33","slug":"android%e5%8a%a8%e6%80%81%e6%8d%a2%e8%82%a4%e5%bc%80%e6%ba%90%e5%ba%93colorful%e5%8f%91%e5%b8%83","status":"publish","type":"post","link":"http:\/\/www.jiandaima.com\/blog\/archives\/252.html","title":{"rendered":"Android\u52a8\u6001\u6362\u80a4\u5f00\u6e90\u5e93Colorful\u53d1\u5e03"},"content":{"rendered":"<p>\u6e90\u7801\u540d\u79f0\uff1aAndroid\u52a8\u6001\u6362\u80a4\u5f00\u6e90\u5e93Colorful<br \/>\n\u6e90\u7801\u7c7b\u578b\uff1a\u5b89\u5353,java<br \/>\n\u6e90\u7801\u5927\u5c0f\uff1a3MB<br \/>\n\u6e90\u7801\u7b80\u4ecb\uff1a\u672cAndroid\u52a8\u6001\u6362\u80a4\u5f00\u6e90\u5e93Colorful,Colorful\u662f\u57fa\u4e8eTheme\uff0c\u65e0\u9700\u91cd\u542fActivity\u3001\u65e0\u9700\u81ea\u5b9a\u4e49View\uff0c\u65b9\u4fbf\u7684\u5b9e\u73b0\u65e5\u95f4\u3001\u591c\u95f4\u6a21\u5f0f<br \/>\n\u6e90\u7801\u6807\u7b7e\uff1aAndroid\u6e90\u7801,Java\u670d\u52a1\u5668\u6e90\u7801,App\u6e90\u7801,\u52a8\u6001\u6362\u80a4\uff0cColorful<br \/>\n\u6e90\u7801\u7b49\u7ea7\uff1a\u2605\u2605\u2605\u2606\u2606<\/p>\n<p>\u6700\u8fd1\u672c\u4eba\u9700\u8981\u7528\u5230\u591c\u95f4\u6a21\u5f0f\uff0c\u4f46\u662f\u7ecf\u8fc7\u4e00\u756a\u641c\u7d22\u4f3c\u4e4e\u5e76\u6ca1\u6709\u770b\u5230\u597d\u7684\u5f00\u6e90\u5b9e\u73b0\uff0c\u770b\u5230\u6709\u4e00\u4e2a\u7c7b\u4f3c\u7684\u5e93MultipleTheme\uff0c\u4f46\u662f\u9700\u8981\u81ea\u5b9a\u4e49\u6240\u6709\u8981\u5b9e\u73b0\u6362\u80a4\u529f\u80fd\u7684View\uff0c\u611f\u89c9\u6bd4\u8f83\u9ebb\u70e6\u3002\u800cPrism\u53c8\u4e0d\u652f\u6301Theme\uff0c\u4e14\u76ee\u524d\u5df2\u7ecf\u4e0d\u518d\u66f4\u65b0\uff0c\u56e0\u6b64\u8fd9\u4e2a\u65b9\u6848\u4e5f\u4e0d\u80fd\u7528\u3002\u5f53\u53d1\u73b0\u73b0\u6709\u7684\u89e3\u51b3\u65b9\u6848\u4e0d\u80fd\u5f88\u597d\u7684\u89e3\u51b3\u95ee\u9898\u65f6\uff0c\u5f80\u5f80\u53ea\u80fd\u81ea\u5df1\u5b9e\u73b0\uff0c\u56e0\u6b64\u672c\u4eba\u82b1\u4e86\u70b9\u65f6\u95f4\u7b80\u5355\u5f04\u4e86\u4e00\u4e2a\u5b9e\u73b0\u8be5\u529f\u80fd\u7684\u5f00\u6e90\u5e93\uff0c\u547d\u540d\u4e3aColorful\u3002<\/p>\n<p>Colorful\u662f\u57fa\u4e8eTheme\uff0c\u65e0\u9700\u91cd\u542fActivity\u3001\u65e0\u9700\u81ea\u5b9a\u4e49View\uff0c\u65b9\u4fbf\u7684\u5b9e\u73b0\u65e5\u95f4\u3001\u591c\u95f4\u6a21\u5f0f\uff0cgithub\u5730\u5740\u4e3a https:\/\/github.com\/bboyfeiyu\/Colorful\u3002<\/p>\n<p>Colorful \u52a8\u6001\u6362\u80a4\u5f00\u6e90\u5e93<\/p>\n<ul>\n<li>\u57fa\u4e8eTheme\u7684Android\u52a8\u6001\u6362\u80a4\u5f00\u6e90\u5e93,\u4ee5\u7b80\u5355\u7684\u65b9\u5f0f\u5b9e\u73b0\u591c\u95f4\u6a21\u5f0f\u3002\n<p>\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n<p><a href=\"http:\/\/www.jiandaima.com\/blog\/wp-content\/uploads\/2016\/03\/QQ\u622a\u56fe20160507124944.png\" class=\"highslide-image\" onclick=\"return hs.expand(this);\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/images.jiandaima.com\/blog\/wp-content\/uploads\/2016\/03\/QQ%E6%88%AA%E5%9B%BE20160507124944-301x500.png\" alt=\"Colorful \u52a8\u6001\u6362\u80a4\u5f00\u6e90\u5e93\" width=\"301\" height=\"500\" class=\"aligncenter size-large wp-image-425\" \/><\/a><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/img.blog.csdn.net\/20150909202110066\" alt=\"http:\/\/img.blog.csdn.net\/20150909202110066\" \/><\/p>\n<p>\u4e00\u3001\u4f7f\u7528\u65b9\u5f0f<br \/>\n<strong>1.1 \u81ea\u5b9a\u4e49\u5c5e\u6027<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n\r\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;\r\n&lt;resources&gt;\r\n \r\n    &lt;!-- \u81ea\u5b9a\u4e49\u5c5e\u6027 --&gt;\r\n    &lt;attr name=&quot;root_view_bg&quot; format=&quot;reference|color&quot; \/&gt;\r\n    &lt;attr name=&quot;btn_bg&quot; format=&quot;reference|color&quot; \/&gt;\r\n    &lt;attr name=&quot;text_color&quot; format=&quot;reference|color&quot; \/&gt;\r\n \r\n&lt;\/resources&gt;\r\n<\/pre>\n<p><strong>1.2 \u5728\u5e03\u5c40\u4e2d\u4f7f\u7528\u81ea\u5b9a\u4e49\u5c5e\u6027\u8bbe\u7f6eView\u7684\u80cc\u666f\u3001\u6587\u672c\u989c\u8272\u7b49\u5c5e\u6027<\/strong><br \/>\nactivity_main.xml\u4e2d\u7684\u5e03\u5c40:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n\r\n&lt;RelativeLayout xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot;\r\n    xmlns:tools=&quot;http:\/\/schemas.android.com\/tools&quot;\r\n    android:id=&quot;@+id\/root_view&quot;\r\n    android:layout_width=&quot;match_parent&quot;\r\n    android:layout_height=&quot;match_parent&quot;\r\n    android:background=&quot;?attr\/root_view_bg&quot;\r\n    tools:context=&quot;com.example.androidthemedemo.MainActivity&quot; &gt;\r\n \r\n    &lt;TextView\r\n        android:id=&quot;@+id\/textview&quot;\r\n        android:layout_width=&quot;match_parent&quot;\r\n        android:layout_height=&quot;wrap_content&quot;\r\n        android:gravity=&quot;center&quot;\r\n        android:text=&quot;@string\/change_theme&quot;\r\n        android:textColor=&quot;?attr\/text_color&quot;\r\n        android:textSize=&quot;20sp&quot; \/&gt;\r\n \r\n    &lt;Button\r\n        android:id=&quot;@+id\/change_btn&quot;\r\n        android:layout_width=&quot;match_parent&quot;\r\n        android:layout_height=&quot;wrap_content&quot;\r\n        android:layout_below=&quot;@id\/textview&quot;\r\n        android:layout_marginTop=&quot;20dp&quot;\r\n        android:text=&quot;@string\/change_theme&quot;\r\n        android:textColor=&quot;?attr\/text_color&quot; \/&gt;\r\n \r\n    &lt;Button\r\n        android:id=&quot;@+id\/second_btn&quot;\r\n        android:layout_width=&quot;match_parent&quot;\r\n        android:layout_height=&quot;wrap_content&quot;\r\n        android:layout_below=&quot;@id\/change_btn&quot;\r\n        android:layout_marginTop=&quot;20dp&quot;\r\n        android:text=&quot;@string\/sec_act&quot;\r\n         \/&gt;\r\n \r\n    &lt;ListView\r\n        android:id=&quot;@+id\/listview&quot;\r\n        android:layout_width=&quot;match_parent&quot;\r\n        android:layout_height=&quot;match_parent&quot;\r\n        android:layout_below=&quot;@id\/second_btn&quot;\r\n        android:layout_marginTop=&quot;20dp&quot; \/&gt;\r\n \r\n&lt;\/RelativeLayout&gt;\r\n<\/pre>\n<p>\u4f8b\u5982\u4e0a\u8ff0\u5e03\u5c40\u4e2d\u6211\u4eec\u5c06root_view\u7684\u80cc\u666f\u8bbe\u7f6e\u4e3a&#8221;?attr\/root_view_bg&#8221;\uff0c\u4ee3\u8868\u5b83\u7684\u80cc\u666f\u662f\u81ea\u5b9a\u4e49\u5c5e\u6027root_view_bg\u7684\u503c\uff0c\u8fd8\u6709Textview\u548cButton\u7684textColor\u5c5e\u6027\u8bbe\u7f6e\u4e3a&#8221;?attr\/text_color&#8221;\u3002<\/p>\n<p><strong>1.3 \u5b9a\u4e49\u591a\u4e2aTheme<\/strong><\/p>\n<p>\u7136\u540e\u5728\u4e0d\u540c\u7684Theme\u4e2d\u4e3a\u8fd9\u4e9b\u5c5e\u6027\u8bbe\u7f6e\u4e0d\u540c\u7684\u503c,\u4f8b\u5982\uff0c\u901a\u5e38\u6211\u4eec\u6709\u65e5\u95f4\u548c\u591c\u95f4\u6a21\u5f0f\u4e24\u79cd\u989c\u8272\u6a21\u5f0f\u3002styles.xml\u4e2d\u7684\u5b8c\u6574\u4ee3\u7801\u5982\u4e0b:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;resources&gt;\r\n\r\n    &lt;style name=&quot;AppBaseTheme&quot; parent=&quot;Theme.AppCompat.Light&quot;&gt;\r\n    &lt;\/style&gt;\r\n\r\n    &lt;!-- Application theme. --&gt;\r\n    &lt;style name=&quot;AppTheme&quot; parent=&quot;AppBaseTheme&quot;&gt;\r\n    &lt;\/style&gt;\r\n\r\n    &lt;!-- \u65e5\u95f4\u4e3b\u9898 --&gt;\r\n    &lt;style name=&quot;DayTheme&quot; parent=&quot;AppTheme&quot;&gt;\r\n        &lt;item name=&quot;root_view_bg&quot;&gt;@drawable\/bg_day&lt;\/item&gt;\r\n        &lt;item name=&quot;btn_bg&quot;&gt;@color\/white_btn_color&lt;\/item&gt;\r\n        &lt;item name=&quot;text_color&quot;&gt;@color\/black_tx_color&lt;\/item&gt;\r\n    &lt;\/style&gt;\r\n\r\n    &lt;!-- \u591c\u95f4\u4e3b\u9898 --&gt;\r\n    &lt;style name=&quot;NightTheme&quot; parent=&quot;AppTheme&quot;&gt;\r\n        &lt;item name=&quot;root_view_bg&quot;&gt;@drawable\/bg_night&lt;\/item&gt;\r\n        &lt;item name=&quot;btn_bg&quot;&gt;@color\/black_btn_color&lt;\/item&gt;\r\n        &lt;item name=&quot;text_color&quot;&gt;@color\/white_tx_color&lt;\/item&gt;\r\n    &lt;\/style&gt;\r\n\r\n&lt;\/resources&gt;\r\n<\/pre>\n<p>\u4e24\u4e2a\u4e3b\u9898\u4e0b\u4e3a\u540c\u4e00\u4e2a\u5c5e\u6027\u8bbe\u7f6e\u4e86\u4e0d\u540c\u7684\u503c\uff0c\u8fbe\u5230\u5207\u6362\u4e3b\u9898\u65f6\u4fee\u6539View\u7684\u76f8\u5173\u5c5e\u6027\u7684\u76ee\u7684\u3002\u4f8b\u5982\u5b9a\u4e49\u5728colors.xml\u4e2d\u7684\u989c\u8272\u503c\u3002<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;\r\n&lt;resources&gt;\r\n\r\n    &lt;!-- \u65e5\u95f4\u6a21\u5f0f --&gt;\r\n    &lt;color name=&quot;white_btn_color&quot;&gt;#3BB32E&lt;\/color&gt;\r\n    &lt;color name=&quot;black_tx_color&quot;&gt;#333333&lt;\/color&gt;\r\n\r\n    &lt;!-- \u591c\u95f4\u6a21\u5f0f --&gt;\r\n    &lt;color name=&quot;black_btn_color&quot;&gt;#aa7788&lt;\/color&gt;\r\n    &lt;color name=&quot;white_tx_color&quot;&gt;#f0f0f0&lt;\/color&gt;\r\n\r\n&lt;\/resources&gt;\r\n<\/pre>\n<p><strong>1.4 \u8bbe\u7f6e\u8981\u4fee\u6539\u7684View\u7684\u5c5e\u6027<\/strong><\/p>\n<p>\u4e0b\u9762\u6211\u4eec\u4e3aactivity_main.xml\u4e2d\u7684\u89c6\u56fe\u8fdb\u884c\u6362\u80a4\u8bbe\u7f6e:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nListView  mNewsListView = (ListView) findViewById(R.id.listview);\r\n\r\n\/\/ \u4e3aListView\u8bbe\u7f6e\u8981\u4fee\u6539\u7684\u5c5e\u6027,\u5728\u8fd9\u91cc\u6ca1\u6709\u5bf9ListView\u672c\u8eab\u7684\u5c5e\u6027\u505a\u4fee\u6539\r\nViewGroupSetter listViewSetter = new ViewGroupSetter(mNewsListView, 0);\r\n\/\/ \u7ed1\u5b9aListView\u7684Item View\u4e2d\u7684news_title\u89c6\u56fe\uff0c\u5728\u6362\u80a4\u65f6\u4fee\u6539\u5b83\u7684text_color\u5c5e\u6027\r\nlistViewSetter.childViewTextColor(R.id.news_title, R.attr.text_color);\r\n\r\n\r\n\/\/ \u6784\u5efaColorful\u5bf9\u8c61\r\nColorful mColorful = new Colorful.Builder(this)\r\n        .backgroundDrawable(R.id.root_view, R.attr.root_view_bg) \/\/ \u8bbe\u7f6eview\u7684\u80cc\u666f\u56fe\u7247\r\n        .backgroundColor(R.id.change_btn, R.attr.btn_bg) \/\/ \u8bbe\u7f6e\u6309\u94ae\u7684\u80cc\u666f\u8272\r\n        .textColor(R.id.textview, R.attr.text_color) \/\/ \u8bbe\u7f6e\u6587\u672c\u989c\u8272\r\n        .setter(listViewSetter)           \/\/ \u624b\u52a8\u8bbe\u7f6esetter\r\n        .create(); \r\n<\/pre>\n<p>\u9996\u5148\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2alistViewSetter\uff0c\u8be5Setter\u7528\u4e8e\u4e3aListView\u7684\u6bcf\u4e2aItem View\u4e2d\u7684news_title\u63a7\u4ef6\u8bbe\u7f6e\u6587\u672c\u989c\u8272\uff0c\u6587\u672c\u989c\u8272\u7684\u503c\u662f\u81ea\u5b9a\u4e49\u5c5e\u6027text_color\u7684\u989c\u8272\u503c\u3002\u7136\u540e\u6784\u5efaColorful\u5bf9\u8c61\uff0c\u5e76\u4e14id\u5206\u522b\u4e3achange_btn\u3001root_view\u3001textview\u7684\u63a7\u4ef6\u7ed1\u5b9a\u7279\u5b9a\u5c5e\u6027\u503c\uff0c\u4f8b\u5982backgroundDrawable(R.id.root_view, R.attr.root_view_bg)\u4ee3\u8868root_view\u7684\u80cc\u666fDrawable\u4e3a\u81ea\u5b9a\u4e49\u5c5e\u6027root_view_bg\u7684\u503c\uff0ctextColor(R.id.textview, R.attr.text_color)\u8868\u793aid\u4e3atextview\u7684TextView\u63a7\u4ef6\u7684\u6587\u672c\u989c\u8272\u4e3aR.attr.text_color\u7684\u503c\u3002\u8fd9\u4e9b\u5c5e\u6027\u90fd\u5728\u4e0d\u540c\u7684Theme\u4e2d\u6709\u4e0d\u540c\u7684\u503c\uff0c\u56e0\u6b64\u5207\u6362Theme\u65f6\u5c31\u4f1a\u53d1\u751f\u53d8\u5316\u3002\u7136\u540e\u6211\u4eec\u5c06listViewSetter\u6dfb\u52a0\u5230Colorful\u5bf9\u8c61\u4e2d\uff0c\u5728\u4fee\u6539\u4e3b\u9898\u65f6\u88ab\u904d\u5386ListView\u4e2d\u7684\u6240\u6709Item View\uff0c\u7136\u540e\u4fee\u6539news_title\u63a7\u4ef6\u7684\u6587\u672c\u989c\u8272\u3002<\/p>\n<p><strong>1.5 \u5207\u6362\u4e3b\u9898<\/strong><br \/>\n\u6700\u540e\u901a\u8fc7Colorful\u5bf9\u8c61\u8bbe\u7f6e\u4e3b\u9898\u5373\u53ef\u5b9e\u73b0\u5207\u6362\uff0c\u4ee3\u7801\u5982\u4e0b:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">boolean isNight = false ;\r\n\r\n\/\/ \u5207\u6362\u4e3b\u9898\r\nprivate void changeThemeWithColorful() {\r\n    if (!isNight) {\r\n        mColorful.setTheme(R.style.DayTheme);\r\n    } else {\r\n        mColorful.setTheme(R.style.NightTheme);\r\n    }\r\n    isNight = !isNight;\r\n}\r\n<\/pre>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Android\u52a8\u6001\u6362\u80a4\u5f00\u6e90\u5e93Colorful,Colorful\u662f\u57fa\u4e8eTheme\uff0c\u65e0\u9700\u91cd\u542fActivity\u3001\u65e0\u9700\u81ea\u5b9a\u4e49View\uff0c\u65b9\u4fbf\u7684\u5b9e\u73b0\u65e5\u95f4\u3001\u591c\u95f4\u6a21\u5f0f<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"toc_depth":0},"categories":[8],"tags":[19,21,24,28,36],"class_list":["post-252","post","type-post","status-publish","format-standard","hentry","category-the-development-of-communication-technology","tag-android","tag-app","tag-colorful","tag-java","tag-36"],"_links":{"self":[{"href":"http:\/\/www.jiandaima.com\/blog\/wp-json\/wp\/v2\/posts\/252","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.jiandaima.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.jiandaima.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.jiandaima.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.jiandaima.com\/blog\/wp-json\/wp\/v2\/comments?post=252"}],"version-history":[{"count":0,"href":"http:\/\/www.jiandaima.com\/blog\/wp-json\/wp\/v2\/posts\/252\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.jiandaima.com\/blog\/wp-json\/wp\/v2\/media?parent=252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.jiandaima.com\/blog\/wp-json\/wp\/v2\/categories?post=252"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.jiandaima.com\/blog\/wp-json\/wp\/v2\/tags?post=252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}