Skip to content Skip to sidebar Skip to footer

How To Clear Color Of A Button?

Not only how to clear color to default color of my button, but also in what moment in my code to do it? I've tried everything but no luck. When I click a button I set some green co

Solution 1:

I just made a simple program which toggles the light filter on and off.

Here is the Activity:

ButtonbuttonClicked=null;
     @OverridepublicvoidonCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
     }

     publicvoidclickedButton(View v) {
         Buttonbutton= (Button)v;
         button.getBackground().setColorFilter(newLightingColorFilter(0xFFFFFFFF,
                                                                       0x66FF33));

         if (buttonClicked != null) {
             buttonClicked.getBackground().setColorFilter(null);
         }
         buttonClicked = button;

     }

and here is the XML

<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"
        ><TextViewandroid:id="@+id/boss"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="Hello World, MyActivity"
            /><Buttonandroid:id="@+id/buttsky"android:layout_below="@id/boss"android:onClick="clickedButton"android:layout_width="200dp"android:layout_height="100dp"android:text="pushMe"
            /><Buttonandroid:id="@+id/buttground"android:layout_below="@id/buttsky"android:onClick="clickedButton"android:layout_width="200dp"android:layout_height="100dp"android:text="no, pushMe"
            /></RelativeLayout>

Post a Comment for "How To Clear Color Of A Button?"