2016-09-08 5 views
0

Ich habe folgend EditText:android verfärben einer Ikone von EditText

editText.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_arrow_bottom_right_black_18dp, 0); 

und ich versuche, die Farbe ic_arrow_bottom_right_black_18dp programmatisch die folgenden Methoden zu ändern:

 protected void setEditTextDisabled(EditText editText) { 
     editText.setFocusable(false); 
     editText.setClickable(false); 
     editText.setEnabled(false); 
     editText.setTextColor(ContextCompat.getColor(getContext(), R.color.package_components_group_text_color)); 
     if (editText.getTag(R.id.values_list_selected_ids) == null) { 
      if (editText.getTag(R.id.values_list_selected_ids) == null) { 
       editText.setFocusableInTouchMode(true); 
       Drawable[] d = editText.getCompoundDrawables(); 
       if (d.length == 4) { 
        d[2].setColorFilter(ContextCompat.getColor(getContext(), R.color.package_components_group_text_color), PorterDuff.Mode.SRC_ATOP); 
       } 
      } 
     } 
     Drawable background = editText.getBackground(); 

     if (background instanceof ShapeDrawable) { 
//   ((ShapeDrawable)background).getPaint().setStroke(2, getResources().getColor(R.color.package_components_group_text_color)); 
//   ((ShapeDrawable)background).getPaint().setStroke(2, getResources().getColor(R.color.package_components_group_text_color)); 

     } else if (background instanceof GradientDrawable) { 
      ((GradientDrawable)background).setStroke(2, getResources().getColor(R.color.package_components_group_text_color)); 
     } else if (background instanceof ColorDrawable) { 
//   ((ColorDrawable)background).setStroke(2, getResources().getColor(R.color.package_components_group_text_color)); 
     } 
    } 

    protected void setEditTextEnabled(EditText editText) { 
     editText.setEnabled(true); 
     editText.setFocusable(true); 
     editText.setClickable(true); 
     editText.setTextColor(ContextCompat.getColor(getContext(), R.color.black)); 
     if (editText.getTag(R.id.values_list_selected_ids) == null) { 
      editText.setFocusableInTouchMode(true); 
      Drawable[] d = editText.getCompoundDrawables(); 
      if (d.length == 4) { 
        d[2].setColorFilter(ContextCompat.getColor(getContext(), R.color.black), PorterDuff.Mode.SRC_ATOP); 
      } 
     } 

     Drawable background = editText.getBackground(); 
     if (background instanceof ShapeDrawable) { 
     // ((ShapeDrawable)background).getPaint().setColor(getResources().getColor(R.color.black)); 
     } else if (background instanceof GradientDrawable) { 
      ((GradientDrawable)background).setStroke(2, getResources().getColor(R.color.black)); 
     } else if (background instanceof ColorDrawable) { 
      // ((ColorDrawable)background).setColor(getResources().getColor(R.color.black)); 
     } 
    } 

Das Problem ist, dass das aufklappbare rechte Icon der EditText unsichtbar oder weiß wird, wenn eine der oben genannten Methoden aufgerufen wird.

Ich habe ein Bild a picture mit dem Symbol des Textes, der auf der rechten Seite befindet.

Antwort

0
This is the right answer 
Drawable ddd = getResources().getDrawable(R.drawable.ic_arrow_bottom_right_black_18dp); 
        Drawable drawable = DrawableCompat.wrap(ddd); 

        DrawableCompat.setTint(drawable, ContextCompat.getColor(getContext(), R.color.package_components_group_text_color)); 

        editText.setCompoundDrawables(null, null, drawable, null); 
1

können Sie Farbe von diesem

EditText lineColorCode = (EditText) findViewById(R.id.line_color_code); 
int color = Color.parseColor("#AE6118"); //The color u want    
lineColorCode.setColorFilter(color); 

ändern oder Sie können dies tun,

Drawable mDrawable = context.getResources().getDrawable(R.drawable.balloons); 
mDrawable.setColorFilter(new 
PorterDuffColorFilter(0xffff00,PorterDuff.Mode.MULTIPLY)); 
+0

Die Methode setColorFilter ist nicht für edittext verfügbar und ich versuche nicht, die edittext-Farbe zu ändern, sondern das Symbol des editiertext. – aurelianr

+0

wenden Sie es auf Symbol –

+0

Wie kann ich das Symbol aus Text bearbeiten? – aurelianr

0

Sie können die Farbe des Symbols nicht mit Picasso Bibliothek Hintergrund ändern. Wenn Sie das Symbol als ImageView erhalten, können Sie das tun. Picasso ist eine sehr einfache und mächtige Bibliothek.