The "right" way to do it is to NOT subclass Button... Create a selector to switch between drawables based on the state of the button and put the file in drawable-nodpi. If the name of your selector file is "my_selector.xml" then you would set the background of your button like so:
android:background="@drawable/my_selector" Thanks, Justin Anderson MagouyaWare Developer http://sites.google.com/site/magouyaware On Mon, Jul 23, 2012 at 2:31 PM, bob <[email protected]> wrote: > I'm trying to make a subclass of Button that is better-looking. It's > called New_Button. > > Right now, I'm trying to make it look different when it is pressed. I > have some code that does this, but I suspect > it's not the "right" way to do it. > > Can someone tell me if this is the "right" way to draw it differently if > it's pressed? > > boolean my_pressed = false; > > public New_Button(Context context, AttributeSet attrs) { > super(context, attrs); > this.setOnTouchListener(new OnTouchListener() { > @Override > public boolean onTouch(View v, MotionEvent event) { > > if (event.getAction()==MotionEvent.ACTION_DOWN) { > my_pressed=true; > invalidate(); > } > if (event.getAction()==MotionEvent.ACTION_UP) { > my_pressed=false; > invalidate(); > } > > return false; > } > }); > > } > > -- > 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 -- 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

