2017-07-26 134 views
0

我有一個textview。我想通過漸變來改變文字的顏色,但它不起作用textcolor的顏色漸變

<shape android:shape="rectangle" > 
     <gradient 
      android:angle="90" 
      android:startColor="#eabd00" 
      android:centerColor="#fef1b2" 
      android:endColor="#f9e273" 
      android:type="linear" /> 
    </shape> 

有人能幫助我嗎?謝謝大家。

回答

0

試試這個

TextView textView = findViewById(R.id.btnLogin) 
Shader textShader=new LinearGradient(0, 0, 0, 20, 
      new int[]{R.color.colorAccent,R.color.colorPrimary}, 
      new float[]{0, 1}, TileMode.CLAMP); 
textView.getPaint().setShader(textShader); 

或本

TextView txt1 = (TextView) findViewById(R.id.textview); 
int[] color = {Color.DKGRAY,Color.CYAN}; 
float[] position = {0, 1}; 
TileMode tile_mode = TileMode.MIRROR; // or TileMode.REPEAT; 
LinearGradient lin_grad = new LinearGradient(0, 0, 0, 50,color,position, tile_mode); 
Shader shader_gradient = lin_grad; 
txt1.getPaint().setShader(shader_gradient);