2013-11-15 56 views
0

我已將以下How to make Button highlight?修改爲此應用程序。如何在點擊時向按鈕添加顏色過濾器?

但是它似乎我不能設置顏色過濾器的按鈕,我已經做到了這一點。我得到的錯誤是The method setColorFilter(PorterDuffColorFilter) is undefined for the type Button,我的理解意味着我不能用它與按鈕對象,但是有沒有辦法解決這個問題?有誰知道我可以如何以類似的方式實現這一點?

我在這裏聲明的過濾器:

//button filter 
    PorterDuffColorFilter greenFilter = new PorterDuffColorFilter(Color.GREEN, PorterDuff.Mode.SRC_ATOP); 

並試圖實現它的按鈕,請點擊這裏:

@Override 
    public void onClick(View v) { 
     // TODO Auto-generated method stub 

     try { 

      String getoffsetlength = offsetLength.getText().toString(); 
      String getoffsetdepth = offsetDepth.getText().toString(); 
      String getductdepth = ductDepth.getText().toString(); 

      double tri1,tri2; 
      double marking1,marking2,marking3; 

      double off1 = Double.parseDouble(getoffsetlength); 
      double off2 = Double.parseDouble(getoffsetdepth); 
      double off3 = Double.parseDouble(getductdepth); 


      //vibrate button onClick 
      myVib.vibrate(20); 

       //change button filter on click 
      calculate.setColorFilter(greenFilter); 




     } catch (NumberFormatException e) { 
      // TODO: handle exception 
      System.out.println("Must enter a numeric value!"); 


     } 
//  
    } 

回答

0

使用的ImageButton,並呼籲.setColorFilter上被設置爲在ImageView的ImageButton的來源。