Merge "docs: add more info about state list drawable and onclick attribute to Button bug:1062898" into froyo
This commit is contained in:
@@ -25,13 +25,13 @@ import android.widget.RemoteViews.RemoteView;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* Represents a push-button widget. Push-buttons can be
|
||||||
* <code>Button</code> represents a push-button widget. Push-buttons can be
|
* pressed, or clicked, by the user to perform an action.
|
||||||
* pressed, or clicked, by the user to perform an action. A typical use of a
|
|
||||||
* push-button in an activity would be the following:
|
* <p>A typical use of a push-button in an activity would be the following:
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* <pre class="prettyprint">
|
* <pre>
|
||||||
* public class MyActivity extends Activity {
|
* public class MyActivity extends Activity {
|
||||||
* protected void onCreate(Bundle icicle) {
|
* protected void onCreate(Bundle icicle) {
|
||||||
* super.onCreate(icicle);
|
* super.onCreate(icicle);
|
||||||
@@ -45,16 +45,52 @@ import android.widget.RemoteViews.RemoteView;
|
|||||||
* }
|
* }
|
||||||
* });
|
* });
|
||||||
* }
|
* }
|
||||||
* }
|
* }</pre>
|
||||||
* </pre>
|
|
||||||
*
|
*
|
||||||
* <p>See the <a href="{@docRoot}resources/tutorials/views/hello-formstuff.html">Form Stuff
|
* <p>However, instead of applying an {@link android.view.View.OnClickListener OnClickListener} to
|
||||||
* tutorial</a>.</p>
|
* the button in your activity, you can assign a method to your button in the XML layout,
|
||||||
|
* using the {@link android.R.attr#onClick android:onClick} attribute. For example:</p>
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* <Button
|
||||||
|
* android:layout_height="wrap_content"
|
||||||
|
* android:layout_width="wrap_content"
|
||||||
|
* android:text="@string/self_destruct"
|
||||||
|
* android:onClick="selfDestruct" /></pre>
|
||||||
|
*
|
||||||
|
* <p>Now, when a user clicks the button, the Android system calls the activity's {@code
|
||||||
|
* selfDestruct(View)} method. In order for this to work, the method must be public and accept
|
||||||
|
* a {@link android.view.View} as its only parameter. For example:</p>
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* public void selfDestruct(View view) {
|
||||||
|
* // Kabloey
|
||||||
|
* }</pre>
|
||||||
|
*
|
||||||
|
* <p>The {@link android.view.View} passed into the method is a reference to the widget
|
||||||
|
* that was clicked.</p>
|
||||||
|
*
|
||||||
|
* <h3>Button style</h3>
|
||||||
|
*
|
||||||
|
* <p>Every Button is styled using the system's default button background, which is often different
|
||||||
|
* from one device to another and from one version of the platform to another. If you're not
|
||||||
|
* satisfied with the default button style and want to customize it to match the design of your
|
||||||
|
* application, then you can replace the button's background image with a <a
|
||||||
|
* href="{@docRoot}guide/topics/resources/drawable-resource.html#StateList">state list drawable</a>.
|
||||||
|
* A state list drawable is a drawable resource defined in XML that changes its image based on
|
||||||
|
* the current state of the button. Once you've defined a state list drawable in XML, you can apply
|
||||||
|
* it to your Button with the {@link android.R.attr#background android:background}
|
||||||
|
* attribute. For more information and an example, see <a
|
||||||
|
* href="{@docRoot}guide/topics/resources/drawable-resource.html#StateList">State List
|
||||||
|
* Drawable</a>.</p>
|
||||||
|
*
|
||||||
|
* <p>Also see the <a href="{@docRoot}resources/tutorials/views/hello-formstuff.html">Form Stuff
|
||||||
|
* tutorial</a> for an example implementation of a button.</p>
|
||||||
*
|
*
|
||||||
* <p><strong>XML attributes</strong></p>
|
* <p><strong>XML attributes</strong></p>
|
||||||
* <p>
|
* <p>
|
||||||
* See {@link android.R.styleable#Button Button Attributes},
|
* See {@link android.R.styleable#Button Button Attributes},
|
||||||
* {@link android.R.styleable#TextView TextView Attributes},
|
* {@link android.R.styleable#TextView TextView Attributes},
|
||||||
* {@link android.R.styleable#View View Attributes}
|
* {@link android.R.styleable#View View Attributes}
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -434,7 +434,7 @@ screen).</dd>
|
|||||||
<h2 id="LayerList">Layer List</h2>
|
<h2 id="LayerList">Layer List</h2>
|
||||||
|
|
||||||
<p>A {@link android.graphics.drawable.LayerDrawable} is a drawable object
|
<p>A {@link android.graphics.drawable.LayerDrawable} is a drawable object
|
||||||
that manages an array of other drawables. Each drawable in the list is drawn in the order of the
|
that manages an array of other drawables. Each drawable in the list is drawn in the order of the
|
||||||
list—the last drawable in the list is drawn on top.</p>
|
list—the last drawable in the list is drawn on top.</p>
|
||||||
|
|
||||||
<p>Each drawable is represented by an {@code <item>} element inside a single {@code
|
<p>Each drawable is represented by an {@code <item>} element inside a single {@code
|
||||||
@@ -641,7 +641,7 @@ In XML: <code>@[<em>package</em>:]drawable/<em>filename</em></code>
|
|||||||
android:state_checkable=["true" | "false"]
|
android:state_checkable=["true" | "false"]
|
||||||
android:state_checked=["true" | "false"]
|
android:state_checked=["true" | "false"]
|
||||||
android:state_enabled=["true" | "false"]
|
android:state_enabled=["true" | "false"]
|
||||||
android:state_window_focused=["true" | "false"] />
|
android:state_window_focused=["true" | "false"] />
|
||||||
</selector>
|
</selector>
|
||||||
</pre>
|
</pre>
|
||||||
</dd>
|
</dd>
|
||||||
@@ -729,12 +729,12 @@ default value should always be last (as demonstrated in the following example).<
|
|||||||
</selector>
|
</selector>
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>This layout XML applies the drawable to a View:</p>
|
<p>This layout XML applies the state list drawable to a Button:</p>
|
||||||
<pre>
|
<pre>
|
||||||
<ImageView
|
<Button
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:src="@drawable/button" />
|
android:background="@drawable/button" />
|
||||||
</pre>
|
</pre>
|
||||||
</dd> <!-- end example -->
|
</dd> <!-- end example -->
|
||||||
|
|
||||||
@@ -1670,13 +1670,13 @@ android:dashGap} is set.</dd>
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:shape="rectangle">
|
android:shape="rectangle">
|
||||||
<gradient
|
<gradient
|
||||||
android:startColor="#FFFF0000"
|
android:startColor="#FFFF0000"
|
||||||
android:endColor="#80FF00FF"
|
android:endColor="#80FF00FF"
|
||||||
android:angle="45"/>
|
android:angle="45"/>
|
||||||
<padding android:left="7dp"
|
<padding android:left="7dp"
|
||||||
android:top="7dp"
|
android:top="7dp"
|
||||||
android:right="7dp"
|
android:right="7dp"
|
||||||
android:bottom="7dp" />
|
android:bottom="7dp" />
|
||||||
<corners android:radius="8dp" />
|
<corners android:radius="8dp" />
|
||||||
</shape>
|
</shape>
|
||||||
|
|||||||
Reference in New Issue
Block a user