-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path5b3ec15499a125805b5bbf8e4afcec8c.html
1 lines (1 loc) · 24.2 KB
/
5b3ec15499a125805b5bbf8e4afcec8c.html
1
{"title":"Buttons","text":"<p>\u539f\u6587\u5730\u5740\uff1a<a rel=\"nofollow\" target=\"_blank\" class=\"external free\" href=\"http:\/\/docs.eoeandroid.com\/guide\/topics\/ui\/controls\/button.html\">http:\/\/docs.eoeandroid.com\/guide\/topics\/ui\/controls\/button.html<\/a>\n<\/p><p>\u8bd1\u6587\u5730\u5740\uff1a<a rel=\"nofollow\" target=\"_blank\" class=\"external free\" href=\"http:\/\/wiki.eoeandroid.com\/Buttons\">http:\/\/wiki.eoeandroid.com\/Buttons<\/a>\n<\/p><p>\u7ffb\u8bd1\uff1afvn\n<\/p><p>\u66f4\u65b0\u65e5\u671f\uff1a2012-07-28\n<\/p>\n<table id=\"toc\" class=\"toc\"><tr><td><div id=\"toctitle\"><h2>\u76ee\u5f55<\/h2><\/div>\n<ul>\n<li class=\"toclevel-1 tocsection-1\"><a href=\"#.E6.8C.89.E9.94.AE_-_Buttons\"><span class=\"tocnumber\">1<\/span> <span class=\"toctext\">\u6309\u952e - Buttons<\/span><\/a>\n<ul>\n<li class=\"toclevel-2 tocsection-2\"><a href=\"#.E7.82.B9.E5.87.BB.E4.BA.8B.E4.BB.B6.E7.9A.84.E5.93.8D.E5.BA.94_-_Responding_to_Click_Events\"><span class=\"tocnumber\">1.1<\/span> <span class=\"toctext\">\u70b9\u51fb\u4e8b\u4ef6\u7684\u54cd\u5e94 - Responding to Click Events<\/span><\/a>\n<ul>\n<li class=\"toclevel-3 tocsection-3\"><a href=\"#.E4.BD.BF.E7.94.A8.E7.9B.91.E5.90.AC.E5.99.A8_-_Using_an_OnClickListener\"><span class=\"tocnumber\">1.1.1<\/span> <span class=\"toctext\">\u4f7f\u7528\u76d1\u542c\u5668 - Using an OnClickListener<\/span><\/a><\/li>\n<\/ul>\n<\/li>\n<li class=\"toclevel-2 tocsection-4\"><a href=\"#.E6.8C.89.E9.92.AE.E7.9A.84.E6.A0.B7.E5.BC.8F_-_Styling_Your_Button\"><span class=\"tocnumber\">1.2<\/span> <span class=\"toctext\">\u6309\u94ae\u7684\u6837\u5f0f - Styling Your Button<\/span><\/a>\n<ul>\n<li class=\"toclevel-3 tocsection-5\"><a href=\"#.E6.97.A0.E8.BE.B9.E6.A1.86.E6.8C.89.E9.92.AE_-_Borderless_button\"><span class=\"tocnumber\">1.2.1<\/span> <span class=\"toctext\">\u65e0\u8fb9\u6846\u6309\u94ae - Borderless button<\/span><\/a><\/li>\n<li class=\"toclevel-3 tocsection-6\"><a href=\"#.E5.AE.9A.E5.88.B6.E8.83.8C.E6.99.AF_-_Custom_background\"><span class=\"tocnumber\">1.2.2<\/span> <span class=\"toctext\">\u5b9a\u5236\u80cc\u666f - Custom background<\/span><\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/td><\/tr><\/table>\n<h1> <span class=\"mw-headline\" id=\".E6.8C.89.E9.94.AE_-_Buttons\">\u6309\u952e - Buttons<\/span><\/h1>\n<p>\u6309\u94ae\u5305\u62ec\u6587\u5b57\u6216\u8005\u56fe\u6807\uff0c\u6216\u8005\u4e24\u8005\u517c\u800c\u6709\u4e4b\uff0c\u5f53\u7528\u6237\u89e6\u6478\u5230\u6309\u94ae\u65f6\u5c31\u4f1a\u89e6\u53d1\u4e8b\u4ef6\u3002\n<\/p><p><img src=\"http:\/\/docs.eoeandroid.com\/images\/ui\/button-types.png\" alt=\"button-types.png\" \/>\n<\/p><p>\u53d6\u51b3\u4e8e\u4f60\u9700\u8981\u6309\u94ae\u6709\u6587\u672c\u3001\u56fe\u6807\u6216\u4e24\u8005\u517c\u800c\u6709\u4e4b\uff0c\u60a8\u53ef\u4ee5\u4ee5\u4e09\u79cd\u65b9\u5f0f\u521b\u5efa\u6309\u94ae\u5e03\u5c40\uff1a\n<\/p><p>\u9700\u8981\u6709\u6587\u5b57\u7684\u6309\u94ae\uff0c\u4f7f\u7528<<a rel=\"nofollow\" target=\"_blank\" class=\"external text\" href=\"http:\/\/docs.eoeandroid.com\/reference\/android\/widget\/Button.html\">Button<\/a>>\u7c7b\uff1a\n<\/p>\n<pre class=\"xml\"><span style=\"color: #009900;\"><span style=\"font-weight: bold; color: black;\"><Button<\/span>\n <span style=\"color: #000066;\">android:layout_width<\/span>=<span style=\"color: #ff0000;\">"wrap_content"<\/span>\n <span style=\"color: #000066;\">android:layout_height<\/span>=<span style=\"color: #ff0000;\">"wrap_content"<\/span>\n <span style=\"color: #000066;\">android:text<\/span>=<span style=\"color: #ff0000;\">"@string\/button_text"<\/span>\n ... <span style=\"font-weight: bold; color: black;\">\/><\/span><\/span><\/pre>\n<p>\u9700\u8981\u6709\u56fe\u6807\u7684\u6309\u94ae\uff0c\u4f7f\u7528<<a rel=\"nofollow\" target=\"_blank\" class=\"external text\" href=\"http:\/\/docs.eoeandroid.com\/reference\/android\/widget\/ImageButton.html\">ImageButton<\/a>>\u7c7b\uff1a\n<\/p>\n<pre class=\"xml\"><span style=\"color: #009900;\"><span style=\"font-weight: bold; color: black;\"><ImageButton<\/span>\n <span style=\"color: #000066;\">android:layout_width<\/span>=<span style=\"color: #ff0000;\">"wrap_content"<\/span>\n <span style=\"color: #000066;\">android:layout_height<\/span>=<span style=\"color: #ff0000;\">"wrap_content"<\/span>\n <span style=\"color: #000066;\">android:src<\/span>=<span style=\"color: #ff0000;\">"@drawable\/button_icon"<\/span>\n ... <span style=\"font-weight: bold; color: black;\">\/><\/span><\/span><\/pre>\n<p>\u9700\u8981\u6709\u6587\u5b57\u548c\u56fe\u6807\u7684\u6309\u94ae\uff0c\u4f7f\u7528\u5177\u6709android:drawableLeft\u5c5e\u6027\u7684<<a rel=\"nofollow\" target=\"_blank\" class=\"external text\" href=\"http:\/\/docs.eoeandroid.com\/reference\/android\/widget\/Button.html\">Button<\/a>>\u7c7b\uff1a\n<\/p>\n<pre class=\"xml\"><span style=\"color: #009900;\"><span style=\"font-weight: bold; color: black;\"><Button<\/span>\n <span style=\"color: #000066;\">android:layout_width<\/span>=<span style=\"color: #ff0000;\">"wrap_content"<\/span>\n <span style=\"color: #000066;\">android:layout_height<\/span>=<span style=\"color: #ff0000;\">"wrap_content"<\/span>\n <span style=\"color: #000066;\">android:text<\/span>=<span style=\"color: #ff0000;\">"@string\/button_text"<\/span>\n <span style=\"color: #000066;\">android:drawableLeft<\/span>=<span style=\"color: #ff0000;\">"@drawable\/button_icon"<\/span>\n ... <span style=\"font-weight: bold; color: black;\">\/><\/span><\/span><\/pre>\n<h2> <span class=\"mw-headline\" id=\".E7.82.B9.E5.87.BB.E4.BA.8B.E4.BB.B6.E7.9A.84.E5.93.8D.E5.BA.94_-_Responding_to_Click_Events\">\u70b9\u51fb\u4e8b\u4ef6\u7684\u54cd\u5e94 - Responding to Click Events<\/span><\/h2>\n<p>\u5f53\u7528\u6237\u70b9\u51fb\u4e00\u4e2a\u6309\u94ae\u65f6\uff0c<<a rel=\"nofollow\" target=\"_blank\" class=\"external text\" href=\"http:\/\/docs.eoeandroid.com\/reference\/android\/widget\/Button.html\">Button<\/a>>\u5bf9\u8c61\u5c31\u4f1a\u6536\u5230\u4e00\u4e2a\u5355\u51fb\u4e8b\u4ef6\u3002\n<\/p><p>\u4e3a\u4e86\u5b9a\u4e49\u4e00\u4e2a\u6309\u94ae\u7684\u70b9\u51fb\u4e8b\u4ef6\u5904\u7406\u7a0b\u5e8f\uff0c\u5728XML\u5e03\u5c40\u4e2d\u4e3a<button>\u5143\u7d20\u6dfb\u52a0<<a rel=\"nofollow\" target=\"_blank\" class=\"external text\" href=\"http:\/\/docs.eoeandroid.com\/reference\/android\/R.attr.html#onClick\">android:onClick<\/a>>\u5c5e\u6027\u3002\u8fd9\u4e2a\u5c5e\u6027\u7684\u503c\u5fc5\u987b\u662f\u4f60\u8981\u8c03\u7528\u7684\u65b9\u6cd5\u54cd\u5e94\u70b9\u51fb\u4e8b\u4ef6\u7684\u540d\u79f0\u3002 \u4f7f\u7528\u8fd9\u4e2a\u5e03\u5c40\u7684<<a rel=\"nofollow\" target=\"_blank\" class=\"external text\" href=\"http:\/\/docs.eoeandroid.com\/reference\/android\/app\/Activity.html\">Activity<\/a>>\u5fc5\u987b\u6267\u884c\u76f8\u5e94\u7684\u65b9\u6cd5\u3002\n<\/p><p>\u4f8b\u5982\uff0c\u8fd9\u91cc\u6709\u4e00\u4e2a\u4f7f\u7528<<a rel=\"nofollow\" target=\"_blank\" class=\"external text\" href=\"http:\/\/docs.eoeandroid.com\/reference\/android\/R.attr.html#onClick\">android:onClick<\/a>>\u5c5e\u6027\u7684\u6309\u94ae\u7684\u5e03\u5c40\uff1a\n<\/p>\n<pre class=\"xml\"><span style=\"color: #009900;\"><span style=\"font-weight: bold; color: black;\"><?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: black;\">?><\/span><\/span>\n<span style=\"color: #009900;\"><span style=\"font-weight: bold; color: black;\"><Button<\/span> <span style=\"color: #000066;\">xmlns:android<\/span>=<span style=\"color: #ff0000;\">"http:\/\/schemas.android.com\/apk\/res\/android"<\/span>\n <span style=\"color: #000066;\">android:id<\/span>=<span style=\"color: #ff0000;\">"@+id\/button_send"<\/span>\n <span style=\"color: #000066;\">android:layout_width<\/span>=<span style=\"color: #ff0000;\">"wrap_content"<\/span>\n <span style=\"color: #000066;\">android:layout_height<\/span>=<span style=\"color: #ff0000;\">"wrap_content"<\/span>\n <span style=\"color: #000066;\">android:text<\/span>=<span style=\"color: #ff0000;\">"@string\/button_send"<\/span>\n <span style=\"color: #000066;\">android:onClick<\/span>=<span style=\"color: #ff0000;\">"sendMessage"<\/span> <span style=\"font-weight: bold; color: black;\">\/><\/span><\/span><\/pre>\n<p>\u5728\u4f7f\u7528\u8fd9\u4e2a\u5e03\u5c40\u7684<<a rel=\"nofollow\" target=\"_blank\" class=\"external text\" href=\"http:\/\/docs.eoeandroid.com\/reference\/android\/app\/Activity.html\">Activity<\/a>>\u4e2d\uff0c\u5229\u7528\u4e0b\u9762\u7684\u65b9\u6cd5\u5904\u7406\u70b9\u51fb\u4e8b\u4ef6\uff1a\n<\/p>\n<pre class=\"java\"><span style=\"color: #808080; font-style: italic;\">\/** Called when the user touches the button *\/<\/span>\n<span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #993333;\">void<\/span> sendMessage<span style=\"color: #66cc66;\">(<\/span><a href=\"http:\/\/www.google.com\/search?hl=en&q=allinurl%3AView+java.sun.com&btnI=I%27m%20Feeling%20Lucky\"><span style=\"color: #aaaadd; font-weight: bold;\">View<\/span><\/a> view<span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\n <span style=\"color: #808080; font-style: italic;\">\/\/ Do something in response to button click<\/span>\n<span style=\"color: #66cc66;\">}<\/span><\/pre>\n<p>\u5728<<a rel=\"nofollow\" target=\"_blank\" class=\"external text\" href=\"http:\/\/docs.eoeandroid.com\/reference\/android\/R.attr.html#onClick\">android:onClick<\/a>>\u5c5e\u6027\u58f0\u660e\u7684\u65b9\u6cd5\u5fc5\u987b\u5b8c\u5168\u6309\u7167\u4e0a\u9762\u663e\u793a\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u8be5\u65b9\u6cd5\u5fc5\u987b\uff1a\n<\/p><p>\u662f\u516c\u5171\u7684\n<\/p><p>\u8fd4\u56devoid\n<\/p><p>\u5b9a\u4e49\u4e00\u4e2a<<a rel=\"nofollow\" target=\"_blank\" class=\"external text\" href=\"http:\/\/docs.eoeandroid.com\/reference\/android\/view\/View.html\">View<\/a>>\u4f5c\u4e3a\u5176\u552f\u4e00\u7684\u53c2\u6570\uff08\u70b9\u51fb\u65f6\u5c06\u4f1a\u770b\u4f5c\u8fd9\u4e2a<<a rel=\"nofollow\" target=\"_blank\" class=\"external text\" href=\"http:\/\/docs.eoeandroid.com\/reference\/android\/view\/View.html\">View<\/a>>\uff09\n<\/p>\n<h3> <span class=\"mw-headline\" id=\".E4.BD.BF.E7.94.A8.E7.9B.91.E5.90.AC.E5.99.A8_-_Using_an_OnClickListener\">\u4f7f\u7528\u76d1\u542c\u5668 - Using an OnClickListener<\/span><\/h3>\n<p>\u60a8\u4e5f\u53ef\u4ee5\u58f0\u660e\u5355\u51fb\u4e8b\u4ef6\u5904\u7406\u7a0b\u5e8f\uff0c\u800c\u4e0d\u662f\u5728XML\u5e03\u5c40\u4e2d\u3002\u8fd9\u53ef\u80fd\u662f\u5fc5\u8981\u7684\uff0c\u5982\u679c\u4f60\u5728\u8fd0\u884c\u65f6\u5b9e\u4f8b\u5316<<a rel=\"nofollow\" target=\"_blank\" class=\"external text\" href=\"http:\/\/docs.eoeandroid.com\/reference\/android\/widget\/Button.html\">Button<\/a>>\uff0c\u6216\u8005\u4f60\u9700\u8981\u5728\u4e00<<a rel=\"nofollow\" target=\"_blank\" class=\"external text\" href=\"http:\/\/docs.eoeandroid.com\/reference\/android\/app\/Fragment.html\">Fragment<\/a>>\u5b50\u7c7b\u4e2d\u58f0\u660e\u5355\u51fb\u4e8b\u4ef6\u3002\n<\/p><p>\u4e3a\u4e86\u58f0\u660e\u4e8b\u4ef6\u5904\u7406\u7a0b\u5e8f\uff0c\u521b\u5efa\u4e00\u4e2a<<a rel=\"nofollow\" target=\"_blank\" class=\"external text\" href=\"http:\/\/docs.eoeandroid.com\/reference\/android\/view\/View.OnClickListener.html\">View.OnClickListener<\/a>>\u5bf9\u8c61\uff0c\u5e76\u901a\u8fc7\u8c03\u7528<<a rel=\"nofollow\" target=\"_blank\" class=\"external text\" href=\"http:\/\/docs.eoeandroid.com\/reference\/android\/view\/View.html#setOnClickListener(android.view.View.OnClickListener)\">setOnClickListener\uff08View.OnClickListener\uff09<\/a>>\u5206\u914d\u7ed9\u6309\u94ae\u3002\u4f8b\u5982\uff1a\n<\/p>\n<pre class=\"java\"><a href=\"http:\/\/www.google.com\/search?hl=en&q=allinurl%3AButton+java.sun.com&btnI=I%27m%20Feeling%20Lucky\"><span style=\"color: #aaaadd; font-weight: bold;\">Button<\/span><\/a> button = <span style=\"color: #66cc66;\">(<\/span><a href=\"http:\/\/www.google.com\/search?hl=en&q=allinurl%3AButton+java.sun.com&btnI=I%27m%20Feeling%20Lucky\"><span style=\"color: #aaaadd; font-weight: bold;\">Button<\/span><\/a><span style=\"color: #66cc66;\">)<\/span> findViewById<span style=\"color: #66cc66;\">(<\/span>R.<span style=\"color: #006600;\">id<\/span>.<span style=\"color: #006600;\">button_send<\/span><span style=\"color: #66cc66;\">)<\/span>;\nbutton.<span style=\"color: #006600;\">setOnClickListener<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #000000; font-weight: bold;\">new<\/span> <a href=\"http:\/\/www.google.com\/search?hl=en&q=allinurl%3AView+java.sun.com&btnI=I%27m%20Feeling%20Lucky\"><span style=\"color: #aaaadd; font-weight: bold;\">View<\/span><\/a>.<span style=\"color: #006600;\">OnClickListener<\/span><span style=\"color: #66cc66;\">(<\/span><span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\n <span style=\"color: #000000; font-weight: bold;\">public<\/span> <span style=\"color: #993333;\">void<\/span> onClick<span style=\"color: #66cc66;\">(<\/span><a href=\"http:\/\/www.google.com\/search?hl=en&q=allinurl%3AView+java.sun.com&btnI=I%27m%20Feeling%20Lucky\"><span style=\"color: #aaaadd; font-weight: bold;\">View<\/span><\/a> v<span style=\"color: #66cc66;\">)<\/span> <span style=\"color: #66cc66;\">{<\/span>\n <span style=\"color: #808080; font-style: italic;\">\/\/ Do something in response to button click<\/span>\n <span style=\"color: #66cc66;\">}<\/span>\n<span style=\"color: #66cc66;\">}<\/span><span style=\"color: #66cc66;\">)<\/span>;<\/pre>\n<h2> <span class=\"mw-headline\" id=\".E6.8C.89.E9.92.AE.E7.9A.84.E6.A0.B7.E5.BC.8F_-_Styling_Your_Button\">\u6309\u94ae\u7684\u6837\u5f0f - Styling Your Button<\/span><\/h2>\n<p>\u6309\u94ae\u7684\u5916\u89c2\uff08\u80cc\u666f\u56fe\u7247\u548c\u5b57\u4f53\uff09\u53ef\u80fd\u4f1a\u56e0\u4e3a\u673a\u5668\u4e0d\u540c\u800c\u6709\u6240\u4e0d\u540c\uff0c\u56e0\u4e3a\u4e0d\u540c\u5382\u5bb6\u7684\u8bbe\u5907\u7684\u8f93\u5165\u63a7\u4ef6\u7684\u9ed8\u8ba4\u6837\u5f0f\u5f80\u5f80\u4e0d\u540c\u3002\n<\/p><p>\u60a8\u53ef\u4ee5\u63a7\u5236\u63a7\u4ef6\u4f7f\u7528\u9002\u7528\u4e8e\u6574\u4e2a\u5e94\u7528\u7a0b\u5e8f\u7684\u6837\u5f0f\u3002\u4f8b\u5982\uff0c\u8981\u786e\u4fdd\u6240\u6709\u8fd0\u884cAndroid4.0\u751a\u81f3\u66f4\u9ad8\u7248\u672c\u7684\u8bbe\u5907\u5728\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528Holo\u4e3b\u9898\uff0c\u9700\u8981\u5728manifest\u7684 <application>\u5143\u7d20\u4e2d\u58f0\u660eandroid:theme=\"@android:style\/Theme.Holo\"\u3002\u901a\u8fc7\u9605\u8bfb\u535a\u5ba2\u6587\u7ae0\u5f97\u77e5\uff0cHolo Everywhere\u4f7f\u7528\u4e86Holo\u7684\u4e3b\u9898\uff0c\u540c\u65f6\u652f\u6301\u4f4e\u7248\u672c\u7684\u8bbe\u5907\u3002\n<\/p><p>\u4e3a\u4e86\u7ed9\u6309\u94ae\u5b9a\u5236\u4e0d\u540c\u7684\u80cc\u666f\uff0c\u6307\u5b9a<<a rel=\"nofollow\" target=\"_blank\" class=\"external text\" href=\"http:\/\/docs.eoeandroid.com\/reference\/android\/R.attr.html#background\">android:background<\/a>>\u5c5e\u6027\u4e3a\u53ef\u7ed8\u5236\u6216\u5f69\u8272\u7684\u8d44\u6e90\u3002\u53e6\u5916\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4e00\u79cd\u7c7b\u4f3c\u4e8eHTML\u7684\u6837\u5f0f\u6765\u5b9a\u4e49\u6309\u94ae\u7684\u6837\u5f0f\uff0c\u53ef\u4ee5\u5b9a\u4e49\u591a\u79cd\u5c5e\u6027\uff0c\u5982\u80cc\u666f\u3001\u5b57\u4f53\u3001\u5927\u5c0f\u7b49\u7b49\u3002\u5173\u4e8e\u5e94\u7528\u6837\u5f0f\u7684\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605<<a rel=\"nofollow\" target=\"_blank\" class=\"external text\" href=\"http:\/\/docs.eoeandroid.com\/guide\/topics\/ui\/themes.html\">Styles and Themes<\/a>>\u3002\n<\/p>\n<h3> <span class=\"mw-headline\" id=\".E6.97.A0.E8.BE.B9.E6.A1.86.E6.8C.89.E9.92.AE_-_Borderless_button\">\u65e0\u8fb9\u6846\u6309\u94ae - Borderless button<\/span><\/h3>\n<p>\u4e00\u79cd\u6709\u7528\u7684\u8bbe\u8ba1\u662f\u65e0\u8fb9\u6846\u6309\u94ae\u3002\u65e0\u8fb9\u6846\u6309\u94ae\u4e0e\u57fa\u672c\u6309\u94ae\u76f8\u4f3c\uff0c\u4f46\u662f\u65e0\u8fb9\u6846\u6309\u94ae\u6ca1\u6709\u65e0\u8fb9\u6846\u6216\u80cc\u666f\uff0c\u4f46\u5728\u4e0d\u540c\u72b6\u6001\u5982\u70b9\u51fb\u65f6\uff0c\u4f1a\u6539\u53d8\u5916\u89c2\u3002\n<\/p><p>\u8981\u521b\u5efa\u4e00\u4e2a\u65e0\u8fb9\u6846\u201c\u6309\u94ae\uff0c\u4e3a\u6309\u94ae\u5e94\u7528<<a rel=\"nofollow\" target=\"_blank\" class=\"external text\" href=\"http:\/\/docs.eoeandroid.com\/reference\/android\/R.attr.html#borderlessButtonStyle\">borderlessButtonStyle<\/a>>\u6837\u5f0f\u3002\u4f8b\u5982\uff1a\n<\/p>\n<pre class=\"java\"><Button\n android:id=<span style=\"color: #ff0000;\">"@+id\/button_send"<\/span>\n android:layout_width=<span style=\"color: #ff0000;\">"wrap_content"<\/span>\n android:layout_height=<span style=\"color: #ff0000;\">"wrap_content"<\/span>\n android:text=<span style=\"color: #ff0000;\">"@string\/button_send"<\/span>\n android:onClick=<span style=\"color: #ff0000;\">"sendMessage"<\/span>\n style=<span style=\"color: #ff0000;\">"?android:attr\/borderlessButtonStyle"<\/span> \/>\n <\/pre>\n<h3> <span class=\"mw-headline\" id=\".E5.AE.9A.E5.88.B6.E8.83.8C.E6.99.AF_-_Custom_background\">\u5b9a\u5236\u80cc\u666f - Custom background<\/span><\/h3>\n<p>\u5982\u679c\u4f60\u60f3\u771f\u6b63\u91cd\u65b0\u5b9a\u4e49\u6309\u94ae\u7684\u5916\u89c2\uff0c\u4f60\u53ef\u4ee5\u6307\u5b9a\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u80cc\u666f\u3002\u800c\u4e0d\u662f\u63d0\u4f9b\u4e00\u4e2a\u7b80\u5355\u7684\u4f4d\u56fe\u6216\u989c\u8272\uff0c\u7136\u800c\uff0c\u4f60\u7684\u80cc\u666f\u5e94\u8be5\u662f\u4e00\u4e2a\u72b6\u6001\u5217\u8868\u8d44\u6e90\uff0c\u53d6\u51b3\u4e8e\u6309\u94ae\u7684\u5f53\u524d\u72b6\u6001\u800c\u6539\u53d8\u5916\u89c2\uff0c\u3002\n<\/p><p>\u60a8\u53ef\u4ee5\u5728\u4e00\u4e2aXML\u6587\u4ef6\u4e2d\u5b9a\u4e49\u72b6\u6001\u5217\u8868\uff0c\u5b9a\u4e49\u4e09\u79cd\u4e0d\u540c\u7684\u56fe\u50cf\u6216\u989c\u8272\uff0c\u7528\u4e8e\u4e0d\u540c\u7684\u6309\u94ae\u72b6\u6001\u3002\n<\/p><p>\u8981\u4e3a\u6309\u94ae\u7684\u80cc\u666f\u521b\u5efa\u4e00\u4e2a\u72b6\u6001\u5217\u8868\u8d44\u6e90\uff1a\n<\/p><p>\u521b\u5efa\u4e09\u4e2a\u6309\u94ae\u80cc\u666f\u4f4d\u56fe\u4ee5\u8868\u793a\u9ed8\u8ba4\u3001\u6309\u4e0b\u548c\u9009\u4e2d\u7684\u6309\u94ae\u72b6\u6001\u3002\n<\/p><p>\u4e3a\u4e86\u786e\u4fdd\u56fe\u50cf\u9002\u5408\u4e0d\u540c\u5927\u5c0f\u7684\u6309\u94ae\uff0c\u4ee5<<a rel=\"nofollow\" target=\"_blank\" class=\"external text\" href=\"http:\/\/docs.eoeandroid.com\/guide\/topics\/graphics\/2d-graphics.html#nine-patch\">9-patch<\/a>>\u7684\u683c\u5f0f\u521b\u5efa\u56fe\u50cf\u3002\n<\/p><p>\u4f4d\u56fe\u653e\u5230\u4f60\u5de5\u7a0b\u7684res\/drawable\/ directory\u3002\u786e\u4fdd\u6bcf\u4e2a\u4f4d\u56fe\u547d\u540d\u6b63\u786e\u80fd\u591f\u53cd\u6620\u5b83\u4eec\u5206\u522b\u4ee3\u8868\u7684\u6309\u94ae\u72b6\u6001\uff0c\u5982button_default.9.png\u3001button_pressed.9.png\u4ee5\u53cabutton_focused.9.png\u3002\n<\/p><p>\u5728res\/drawable\/ directory\u4e0b\u521b\u5efa\u4e00\u4e2a\u65b0\u7684XML\u6587\u4ef6\uff08\u547d\u540d\u7c7b\u4f3c\u4e8ebutton_custom.xml\uff09\u3002\u4f7f\u7528\u4e0b\u9762\u7684XML\uff1a\n<\/p>\n<pre class=\"xml\"><span style=\"color: #009900;\"><span style=\"font-weight: bold; color: black;\"><?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: black;\">?><\/span><\/span>\n<span style=\"color: #009900;\"><span style=\"font-weight: bold; color: black;\"><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: black;\">><\/span><\/span>\n <span style=\"color: #009900;\"><span style=\"font-weight: bold; color: black;\"><item<\/span> <span style=\"color: #000066;\">android:drawable<\/span>=<span style=\"color: #ff0000;\">"@drawable\/button_pressed"<\/span>\n <span style=\"color: #000066;\">android:state_pressed<\/span>=<span style=\"color: #ff0000;\">"true"<\/span> <span style=\"font-weight: bold; color: black;\">\/><\/span><\/span>\n <span style=\"color: #009900;\"><span style=\"font-weight: bold; color: black;\"><item<\/span> <span style=\"color: #000066;\">android:drawable<\/span>=<span style=\"color: #ff0000;\">"@drawable\/button_focused"<\/span>\n <span style=\"color: #000066;\">android:state_focused<\/span>=<span style=\"color: #ff0000;\">"true"<\/span> <span style=\"font-weight: bold; color: black;\">\/><\/span><\/span>\n <span style=\"color: #009900;\"><span style=\"font-weight: bold; color: black;\"><item<\/span> <span style=\"color: #000066;\">android:drawable<\/span>=<span style=\"color: #ff0000;\">"@drawable\/button_default"<\/span> <span style=\"font-weight: bold; color: black;\">\/><\/span><\/span>\n<span style=\"color: #009900;\"><span style=\"font-weight: bold; color: black;\"><\/selector<span style=\"font-weight: bold; color: black;\">><\/span><\/span><\/span><\/pre>\n<p>\u8fd9\u5b9a\u4e49\u4e00\u4e2a\u5355\u4e00\u7684\u7ed8\u5236\u8d44\u6e90\uff0c\u5c06\u57fa\u4e8e\u6309\u94ae\u7684\u5f53\u524d\u72b6\u6001\u6539\u53d8\u5176\u56fe\u50cf\u3002\n<\/p><p>\u7b2c\u4e00\u4e2a<item>\u5b9a\u4e49\u4e86\u6309\u4e0b\u6309\u94ae\uff08\u6fc0\u6d3b\uff09\u65f6\u4f7f\u7528\u7684\u4f4d\u56fe\u3002\n<\/p><p>\u7b2c\u4e8c\u4e2a<item>\u5b9a\u4e49\u4e86\u6309\u94ae\u6309\u4e0b\u65f6\uff08\u6309\u94ae\u9ad8\u4eae\u65f6\uff0c\u4f7f\u7528\u8f68\u8ff9\u7403\u6216\u65b9\u5411\u952e\uff09\u4f7f\u7528\u7684\u4f4d\u56fe\u3002\n<\/p><p>\u7b2c\u4e09\u4e2a<item>\u5b9a\u4e49\u4e86\u9ed8\u8ba4\u72b6\u6001\u4e0b\u7684\u6309\u94ae\uff08\u65e2\u4e0d\u662f\u6309\u4e0b\u4e5f\u4e0d\u662f\u9009\u4e2d\uff09\u4f7f\u7528\u7684\u4f4d\u56fe\u3002\n<\/p>\n<div style=\"margin: 1em 0; padding: 10px; overflow: auto; background: #F7F7F7; border-left:4px solid; border-color:#258AAF;\">\n<p>\u6ce8\u610f\uff1a<item>\u5143\u7d20\u7684\u987a\u5e8f\u662f\u91cd\u8981\u7684\u3002\u5f53\u56fe\u50cf\u53ef\u7528\u65f6\uff0c\u6309\u987a\u5e8f\u904d\u5386<item>\u5143\u7d20\uff0c\u4ee5\u786e\u5b9a\u54ea\u4e00\u4e2a\u9002\u5408\u5f53\u524d\u6309\u94ae\u72b6\u6001\u3002\u56e0\u4e3a\u9ed8\u8ba4\u7684\u4f4d\u56fe\u5728\u6700\u540e\uff0c\u5f53android:state_pressed \u548candroid:state_focused\u7684\u503c\u90fd\u4e3afalse\u65f6\u624d\u4f1a\u88ab\u5e94\u7528\u3002\n<\/p>\n<\/div>\n<p>\u73b0\u5728\u8fd9\u4e2aXML\u6587\u4ef6\u4ee3\u8868\u4e00\u4e2a\u5355\u4e00\u7684\u7ed8\u5236\u8d44\u6e90\uff0c\u5f53<<a rel=\"nofollow\" target=\"_blank\" class=\"external text\" href=\"http:\/\/docs.eoeandroid.com\/reference\/android\/widget\/Button.html\">Button<\/a>>\u5f15\u7528\u5b83\u4f5c\u4e3a\u80cc\u666f\uff0c\u56fe\u50cf\u5c06\u57fa\u4e8e\u6309\u94ae\u7684\u4e09\u79cd\u72b6\u6001\u800c\u6539\u53d8\u3002\n<\/p><p>\u7136\u540e\uff0c\u53ea\u9700\u5e94\u7528\u6b64XML\u6587\u4ef6\u4f5c\u4e3a\u6309\u94ae\u7684\u80cc\u666f\uff1a\n<\/p>\n<pre class=\"java\"><Button\n android:id=<span style=\"color: #ff0000;\">"@+id\/button_send"<\/span>\n android:layout_width=<span style=\"color: #ff0000;\">"wrap_content"<\/span>\n android:layout_height=<span style=\"color: #ff0000;\">"wrap_content"<\/span>\n android:text=<span style=\"color: #ff0000;\">"@string\/button_send"<\/span>\n android:onClick=<span style=\"color: #ff0000;\">"sendMessage"<\/span>\n android:background=<span style=\"color: #ff0000;\">"@drawable\/button_custom"<\/span> \/><\/pre>\n<p>\u5bf9\u4e8e\u6b64XML\u8bed\u6cd5\u7684\u66f4\u591a\u8be6\u7ec6\u4fe1\u606f\uff0c\u5305\u62ec\u5982\u4f55\u5b9a\u4e49\u4e00\u4e2a\u975e\u4f7f\u80fd\u3001\u4e0d\u786e\u5b9a\u7684\u6216\u5176\u4ed6\u7684\u6309\u94ae\u72b6\u6001\uff0c\u9605\u8bfb<<a rel=\"nofollow\" target=\"_blank\" class=\"external text\" href=\"http:\/\/docs.eoeandroid.com\/guide\/topics\/resources\/drawable-resource.html#StateList\">State List Drawable<\/a>>\u3002\n<\/p>"}