tags:

views:

96

answers:

2

Hi, I am working on Android Application. I want to have 4 buttons to be placed horizontally at the bottom of the screen.In these 4 buttons 2 buttons are having images on them.The border of the buttons should be black color and the border should be as thin as possible.When I click the button, I want the back ground of the button should be changed to blue color with out the color of border to be changed and should be remained in that color for some time. How can I achieve this scenario in Android.


Any help is Appreciated
Thanks in Adavance,

+1  A: 

Hai refer this,

        boolean check=false;
        Button backward_img;        Button backward_img1;
         backward_img = (Button) findViewById(R.id.bars_footer_backward);
         backward_img1 = (Button) findViewById(R.id.bars_footer_backward1);
    backward_img.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
                              check=true;
                    backward_img.setBackgroundColor(Color.BLUE);
                }

            });

        if(check== true)
{
            backward_img1.setBackgroundColor(Color.RED);
            backward_img.setBackgroundColor(Color.BLUE);
}
Tilsan The Fighter
This will set the BG permanently, that is, if the user clicks the back button, the background will be red.
methode
@methode: ok refer the new answer i have corrected the oldanswer
Tilsan The Fighter
+3  A: 

One approach is to create an XML file like this in drawable, called whatever.xml:

<?xml version="1.0" encoding="utf-8"?> 
  <selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; 
      <item android:state_focused="true" android:state_pressed="true" 
            android:drawable="@drawable/bgalt" /> 
      <item android:state_focused="false" android:state_pressed="true" 
            android:drawable="@drawable/bgalt" /> 
      <item android:drawable="@drawable/bgnorm" /> 
  </selector>

bgalt and bgnormare PNG images in drawable.

If you create the buttons programatically in your activity, you can set the background with:

final Button b = new Button (MyClass.this);
b.setBackgroundDrawable(getResources().getDrawable(R.drawable.whatever));

If you set your buttons' style with an XML, you would do something like:

<Button
  android:id="@+id/mybutton"
  android:background="@drawable/watever" />

I'll try to find you a link to a tutorial. Hope this helps.

methode
http://developer.android.com/reference/android/widget/ImageButton.html
methode
You can also replace those drawables in the XML file with colors definitions if you want to avoid using images.
haseman