Android Tutorial-Making a custom Android button using a custom view
Creating a custom view is as simple as inheriting from the View class and overriding the methods that need to be overridden. In this example, a custom button is implemented in this way. The button shall feature a labelled image (i.e. an image with text underneath).
1 public class CustomImageButton extends View {
2 private final static int WIDTH_PADDING = 8;
3 private final static int HEIGHT_PADDING = 10;
4 private final String label;
5 private final int imageResId;
6 private final Bitmap image;
7 private final InternalListener listenerAdapter = new InternalListener();
8
The constructor can take in the parameters to set the button image and label.
9 /**
10 * Constructor.
11 *
12 * @param context
13 * Activity context in which the button view is being placed for.
14 *
15 * @param resImage
16 * Image to put on the button. This image should have been placed
17 * in the drawable resources directory.
18 *
19 * @param label
20 * The text label to display for the custom button.
21 */
22 public CustomImageButton(Context context, int resImage, String label)
23 {
24 super(context);
25 this.label = label;
26 this.imageResId = resImage;
27 this.image = BitmapFactory.decodeResource(context.getResources(),
28 imageResId);
29
30 setFocusable(true);
31 setBackgroundColor(Color.WHITE);
32
33 setOnClickListener(listenerAdapter);
34 setClickable(true);
35 }
36
With the constructor defined, there are a number of methods in the View class that needs to be overridden to this view behave like a button. Firstly, the onFocusChanged gets triggered when the focus moves onto or off the view. In the case of our custom button, we want the button to be “highlighted” when ever the focus is on the button.
This android tutorial to create and android button has been taken from the android development
tutorial by androidcore click the link to read the rest of the android tutorial
learn android programming
18 comments:
redirected xanax for anxiety and sleep - xanax online no prescription overnight
this site xanax side effects mayo clinic
buy ambien online took 3 ambien cr - ambien drug interactions oxycodone
tramadol online buy tramadol online cash on delivery - need purchase tramadol
Visit Website 2mg klonopin equal - generic form of klonopin
buy retin a retin a cream generic name - retin a cream tube size
more helpful hints xanax side effects sexually - generic xanax thailand
address where to buy ambien cr online - ambien online no prescription mastercard
valium online valium en diazepam - what is valium pill used for
ambien online price of ambien per pill - ambien side effects withdrawal
buy ephedrine ephedrine facts - ephedrine kids
continue ephedra cones - ephedrine purchase
this site generic xanax pill identification - different types xanax pills
buy valium online purchasing valium online legal - where can i buy real valium online
generic valium valium anxiety symptoms - how long will 10mg valium last
smCSihI streaming free ku 12 years a slave watch online free stkw LsENZlP onli
Find Out More xanax drug forum - much do xanax pills cost street
site internet much does 1mg xanax sell - xanax doses
Post a Comment