• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.widget;
18 
19 import android.content.Context;
20 import android.os.Handler;
21 import android.os.Message;
22 import android.util.AttributeSet;
23 import android.view.MotionEvent;
24 import android.widget.RemoteViews.RemoteView;
25 
26 import java.util.Map;
27 
28 /**
29  * <p>
30  * Displays a button with an image (instead of text) that can be pressed
31  * or clicked by the user. By default, an ImageButton looks like a regular
32  * {@link android.widget.Button}, with the standard button background
33  * that changes color during different button states. The image on the surface
34  * of the button is defined either by the {@code android:src} attribute in the
35  * {@code &lt;ImageButton&gt;} XML element or by the
36  * {@link #setImageResource(int)} method.</p>
37  *
38  * <p>To remove the standard button background image, define your own
39  * background image or set the background color to be transparent.</p>
40  * <p>To indicate the different button states (focused, selected, etc.), you can
41  * define a different image for each state. E.g., a blue image by default, an
42  * orange one for when focused, and a yellow one for when pressed. An easy way to
43  * do this is with an XML drawable "selector." For example:</p>
44  * <pre>
45  * &lt;?xml version="1.0" encoding="utf-8"?&gt;
46  * &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
47  *     &lt;item android:drawable="@drawable/button_normal" /&gt; &lt;!-- default --&gt;
48  *     &lt;item android:state_pressed="true"
49  *           android:drawable="@drawable/button_pressed" /&gt; &lt;!-- pressed --&gt;
50  *     &lt;item android:state_focused="true"
51  *           android:drawable="@drawable/button_focused" /&gt; &lt;!-- focused --&gt;
52  * &lt;/selector&gt;</pre>
53  *
54  * <p>Save the XML file in your project {@code res/drawable/} folder and then
55  * reference it as a drawable for the source of your ImageButton (in the
56  * {@code android:src} attribute). Android will automatically change the image
57  * based on the state of the button and the corresponding images
58  * defined in the XML.</p>
59  *
60  * <p><strong>XML attributes</strong></p>
61  * <p>
62  * See {@link android.R.styleable#ImageView Button Attributes},
63  * {@link android.R.styleable#View View Attributes}
64  * </p>
65  */
66 @RemoteView
67 public class ImageButton extends ImageView {
ImageButton(Context context)68     public ImageButton(Context context) {
69         this(context, null);
70     }
71 
ImageButton(Context context, AttributeSet attrs)72     public ImageButton(Context context, AttributeSet attrs) {
73         this(context, attrs, com.android.internal.R.attr.imageButtonStyle);
74     }
75 
ImageButton(Context context, AttributeSet attrs, int defStyle)76     public ImageButton(Context context, AttributeSet attrs, int defStyle) {
77         super(context, attrs, defStyle);
78         setFocusable(true);
79     }
80 
81     @Override
onSetAlpha(int alpha)82     protected boolean onSetAlpha(int alpha) {
83         return false;
84     }
85 }
86