I'm trying to create a simple on a black background view with 2 (maybe
3) clickable images which toggle between 2 graphics each depending on
whether they are clicked or not.  My code is below, I have the
following issues:

1) Using "StateListDrawable", I can get the buttons to change state
when user navigates up/down, but they do not seem to respond to touch
screen events (standard Button and ImageButtons do).
2) I haven't figured out yet how to handle button click events (but
ignore navigating from one to the other by up/down key presses)
3) The background is not all black
4) I want the buttons to be centered vertically, currently the first
one is right at the top of the screen.


class CustomImageButton extends Button { // View { //ImageButton {
        public CustomImageButton(Context context, Bitmap imgSelected, Bitmap
imgInactive ) {
                super(context);
                Drawable dSelected = new BitmapDrawable(imgSelected);
                Drawable dInactive = new BitmapDrawable(imgInactive);

                StateListDrawable images = new StateListDrawable();
                images.addState(Button.ENABLED_FOCUSED_STATE_SET, dSelected);
                //images.addState(Button.PRESSED_SELECTED_STATE_SET, dSelected);
                images.addState(Button.PRESSED_ENABLED_SELECTED_STATE_SET,
dSelected);
                images.addState(Button.EMPTY_STATE_SET, dInactive);
                setBackgroundDrawable( images );

                this.setWidth( imgSelected.getWidth() );
                this.setHeight( imgSelected.getHeight() );
                //setBackgroundColor(0);
                //this.setFocusableInTouchMode(true);
        }
}

class MyCanvas extends LinearLayout {
        public MyCanvas(Context context) { //throws IOException {
                super(context);
                this.setOrientation(VERTICAL);
                setBackgroundColor(0);


                Bitmap image = 
BitmapFactory.decodeResource(context.getResources(),
R.drawable.combinedImages);
                int width = image.getWidth() / 3;
                int height = image.getHeight();

                splash = Bitmap.createBitmap( image, image.getWidth()-width, 0,
width, height );

                height >>= 1;
                View button1 = new CustomImageButton(context, true,
                                Bitmap.createBitmap( image, 0, 0, width, height 
),
                                Bitmap.createBitmap( image, width, 0, width, 
height ) );
                addView( button1 );

                View button2 = new CustomImageButton(context, false,
                                Bitmap.createBitmap( image, width, height, 
width, height ),
                                Bitmap.createBitmap( image, 0, height, width, 
height ) );
                addView( button2 );
        }
}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to