2014-03-31 34 views
0

在我的佈局文件中,我沒有明確定義我的ButtonView的文本顏色,所以在運行時它呈現爲默認顏色(這是黑色)。android應用:按鈕的明文顏色

爲了響應用戶輸入,我將使用setTextColor()方法將我的按鈕的文本顏色設置爲紅色。然後,爲了響應另一個用戶輸入,我需要恢復爲默認顏色。什麼是實現它的最好方法?我正在尋找clearTextColor()方法,但沒有找到。

回答

0

你可以通過設置顏色爲黑色像這樣重新設置: text.setTextColor(Color.BLACK),或text.setTextColor(Color.rgb(0,0,0))

1

有沒有保證默認顏色可以是黑色的,因爲每個OEM可以定製android平臺。

您可以使用ValueAnimator設置文本顏色和重置需要

的時候,這裏是一個示例代碼爲默認顏色。

改變顏色

final Button button = (Button)findViewById(R.id.button); 
    final ValueAnimator colorAnimation2 = ValueAnimator.ofObject(new ArgbEvaluator(), button.getCurrentTextColor(), Color.RED); 

    colorAnimation2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 

     @Override 
     public void onAnimationUpdate(ValueAnimator animator) { 
      button.setTextColor((Integer) animator.getAnimatedValue()); 
     } 
    }); 
    colorAnimation2.start(); 

重置爲默認顏色

colorAnimation2.reverse();