Skip to content

Commit 5b7328f

Browse files
scottamainAndroid (Google) Code Review
authored andcommitted
Merge "docs: add more info about state list drawable and onclick attribute to Button bug:1062898" into froyo
2 parents 27de3a2 + 6ec3d4f commit 5b7328f

File tree

2 files changed

+57
-21
lines changed

2 files changed

+57
-21
lines changed

core/java/android/widget/Button.java

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525

2626

2727
/**
28-
* <p>
29-
* <code>Button</code> represents a push-button widget. Push-buttons can be
30-
* pressed, or clicked, by the user to perform an action. A typical use of a
31-
* push-button in an activity would be the following:
28+
* Represents a push-button widget. Push-buttons can be
29+
* pressed, or clicked, by the user to perform an action.
30+
31+
* <p>A typical use of a push-button in an activity would be the following:
3232
* </p>
3333
*
34-
* <pre class="prettyprint">
34+
* <pre>
3535
* public class MyActivity extends Activity {
3636
* protected void onCreate(Bundle icicle) {
3737
* super.onCreate(icicle);
@@ -45,16 +45,52 @@
4545
* }
4646
* });
4747
* }
48-
* }
49-
* </pre>
48+
* }</pre>
49+
*
50+
* <p>However, instead of applying an {@link android.view.View.OnClickListener OnClickListener} to
51+
* the button in your activity, you can assign a method to your button in the XML layout,
52+
* using the {@link android.R.attr#onClick android:onClick} attribute. For example:</p>
53+
*
54+
* <pre>
55+
* &lt;Button
56+
* android:layout_height="wrap_content"
57+
* android:layout_width="wrap_content"
58+
* android:text="@string/self_destruct"
59+
* android:onClick="selfDestruct" /&gt;</pre>
60+
*
61+
* <p>Now, when a user clicks the button, the Android system calls the activity's {@code
62+
* selfDestruct(View)} method. In order for this to work, the method must be public and accept
63+
* a {@link android.view.View} as its only parameter. For example:</p>
5064
*
51-
* <p>See the <a href="{@docRoot}resources/tutorials/views/hello-formstuff.html">Form Stuff
52-
* tutorial</a>.</p>
65+
* <pre>
66+
* public void selfDestruct(View view) {
67+
* // Kabloey
68+
* }</pre>
69+
*
70+
* <p>The {@link android.view.View} passed into the method is a reference to the widget
71+
* that was clicked.</p>
72+
*
73+
* <h3>Button style</h3>
74+
*
75+
* <p>Every Button is styled using the system's default button background, which is often different
76+
* from one device to another and from one version of the platform to another. If you're not
77+
* satisfied with the default button style and want to customize it to match the design of your
78+
* application, then you can replace the button's background image with a <a
79+
* href="{@docRoot}guide/topics/resources/drawable-resource.html#StateList">state list drawable</a>.
80+
* A state list drawable is a drawable resource defined in XML that changes its image based on
81+
* the current state of the button. Once you've defined a state list drawable in XML, you can apply
82+
* it to your Button with the {@link android.R.attr#background android:background}
83+
* attribute. For more information and an example, see <a
84+
* href="{@docRoot}guide/topics/resources/drawable-resource.html#StateList">State List
85+
* Drawable</a>.</p>
86+
*
87+
* <p>Also see the <a href="{@docRoot}resources/tutorials/views/hello-formstuff.html">Form Stuff
88+
* tutorial</a> for an example implementation of a button.</p>
5389
*
5490
* <p><strong>XML attributes</strong></p>
55-
* <p>
56-
* See {@link android.R.styleable#Button Button Attributes},
57-
* {@link android.R.styleable#TextView TextView Attributes},
91+
* <p>
92+
* See {@link android.R.styleable#Button Button Attributes},
93+
* {@link android.R.styleable#TextView TextView Attributes},
5894
* {@link android.R.styleable#View View Attributes}
5995
* </p>
6096
*/

docs/html/guide/topics/resources/drawable-resource.jd

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ screen).</dd>
434434
<h2 id="LayerList">Layer List</h2>
435435

436436
<p>A {@link android.graphics.drawable.LayerDrawable} is a drawable object
437-
that manages an array of other drawables. Each drawable in the list is drawn in the order of the
437+
that manages an array of other drawables. Each drawable in the list is drawn in the order of the
438438
list&mdash;the last drawable in the list is drawn on top.</p>
439439

440440
<p>Each drawable is represented by an {@code &lt;item&gt;} element inside a single {@code
@@ -641,7 +641,7 @@ In XML: <code>@[<em>package</em>:]drawable/<em>filename</em></code>
641641
android:state_checkable=["true" | "false"]
642642
android:state_checked=["true" | "false"]
643643
android:state_enabled=["true" | "false"]
644-
android:state_window_focused=["true" | "false"] />
644+
android:state_window_focused=["true" | "false"] />
645645
&lt;/selector>
646646
</pre>
647647
</dd>
@@ -729,12 +729,12 @@ default value should always be last (as demonstrated in the following example).<
729729
&lt;/selector>
730730
</pre>
731731

732-
<p>This layout XML applies the drawable to a View:</p>
732+
<p>This layout XML applies the state list drawable to a Button:</p>
733733
<pre>
734-
&lt;ImageView
734+
&lt;Button
735735
android:layout_height="wrap_content"
736736
android:layout_width="wrap_content"
737-
android:src="@drawable/button" />
737+
android:background="@drawable/button" />
738738
</pre>
739739
</dd> <!-- end example -->
740740

@@ -1670,13 +1670,13 @@ android:dashGap} is set.</dd>
16701670
&lt;?xml version="1.0" encoding="utf-8"?>
16711671
&lt;shape xmlns:android="http://schemas.android.com/apk/res/android"
16721672
android:shape="rectangle">
1673-
&lt;gradient
1674-
android:startColor="#FFFF0000"
1673+
&lt;gradient
1674+
android:startColor="#FFFF0000"
16751675
android:endColor="#80FF00FF"
16761676
android:angle="45"/>
1677-
&lt;padding android:left="7dp"
1677+
&lt;padding android:left="7dp"
16781678
android:top="7dp"
1679-
android:right="7dp"
1679+
android:right="7dp"
16801680
android:bottom="7dp" />
16811681
&lt;corners android:radius="8dp" />
16821682
&lt;/shape>

0 commit comments

Comments
 (0)