Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Button setAlpha
    primarykey
    data
    text
    <p>There are a set of buttons, I want to get the result:</p> <p>When I click one of them, first I divide them into two parts: the clicked one and the others. I'm trying to set different color or alpha value to different them.</p> <p>Now I use <code>setAlpha</code>, but when I change the value from <strong>0 to 255</strong>, it works, but when I change the value from <strong>255 to 0</strong> , it doesnot work. I don't know why.</p> <p>Maybe after I invoke the method<code>Button.setAlpha()</code>, I need invoke another method?</p> <p>my code:</p> <pre><code>public class MainActivity extends Activity { // button alpha value: minimize value public static int BUTTON_ALPHA_MIN = 0; // button alpha value: maximize value public static int BUTTON_ALPHA_MAX = 255; private LinearLayout centerRegion; private LinearLayout bottomRegion; private Button btnCheckIn; private Button btnReview; private Button btnMyCircles; private Button btnSettings; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // get all the widgets getAllWidgets(); // set buttons click response function btnCheckIn.setOnClickListener(new OnClickListener() { public void onClick(View v) { centerRegion.setBackgroundColor(android.graphics.Color.RED); btnReview.getBackground().setAlpha(BUTTON_ALPHA_MIN); btnMyCircles.getBackground().setAlpha(BUTTON_ALPHA_MIN); btnSettings.getBackground().setAlpha(BUTTON_ALPHA_MIN); btnCheckIn.getBackground().setAlpha(BUTTON_ALPHA_MAX); } }); btnReview.setOnClickListener(new OnClickListener() { public void onClick(View v) { centerRegion.setBackgroundColor(android.graphics.Color.BLUE); btnCheckIn.getBackground().setAlpha(BUTTON_ALPHA_MIN); btnMyCircles.getBackground().setAlpha(BUTTON_ALPHA_MIN); btnSettings.getBackground().setAlpha(BUTTON_ALPHA_MIN); btnReview.getBackground().setAlpha(BUTTON_ALPHA_MAX); } }); btnMyCircles.setOnClickListener(new OnClickListener() { public void onClick(View v) { centerRegion.setBackgroundColor(android.graphics.Color.YELLOW); btnCheckIn.getBackground().setAlpha(BUTTON_ALPHA_MAX); btnReview.getBackground().setAlpha(BUTTON_ALPHA_MAX); btnSettings.getBackground().setAlpha(BUTTON_ALPHA_MAX); v.getBackground().setAlpha(BUTTON_ALPHA_MIN); } }); btnSettings.setOnClickListener(new OnClickListener() { public void onClick(View v) { centerRegion.setBackgroundColor(android.graphics.Color.MAGENTA); btnCheckIn.getBackground().setAlpha(BUTTON_ALPHA_MAX); btnReview.getBackground().setAlpha(BUTTON_ALPHA_MAX); btnMyCircles.getBackground().setAlpha(BUTTON_ALPHA_MAX); v.getBackground().setAlpha(BUTTON_ALPHA_MIN); } }); } /** * get all the widgets */ public void getAllWidgets() { this.centerRegion = (LinearLayout) this.findViewById(R.id.center_region); this.bottomRegion = (LinearLayout) this.findViewById(R.id.bottom_region); this.btnCheckIn = (Button) this.findViewById(R.id.button_check_in); this.btnReview = (Button) this.findViewById(R.id.button_review); this.btnMyCircles = (Button) this.findViewById(R.id.button_my_circles); this.btnSettings = (Button) this.findViewById(R.id.button_setting); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload