Vla*_*ker 4 android android-edittext android-support-library android-drawable
美好的一天.我有一个问题.我将EditText drawable的颜色更改为焦点,并在焦点更改时将其更改为默认颜色.一切都很好,直到支持库更新(这是我的假设)现在,drawable的颜色不会切换回正常.感谢大家提前=)
这是我的代码:
@Override
public Drawable setTint(Drawable d, int color) {
Drawable wrappedDrawable = DrawableCompat.wrap(d);
DrawableCompat.setTint(wrappedDrawable, color);
return wrappedDrawable;
}
@Override
public void setEditTextDrawables(final EditText editText, final int drawable) {
editText.setCompoundDrawablesWithIntrinsicBounds(drawable, 0, 0, 0);
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
if (b){
Drawable icon = getResources().getDrawable(drawable);
editText.setCompoundDrawablesWithIntrinsicBounds(setTint(icon,
getResources().getColor(R.color.colorAccent)), null, null, null);
}else if (!b){
Drawable icon = getResources().getDrawable(drawable);
editText.setCompoundDrawablesWithIntrinsicBounds(setTint(icon,
getResources().getColor(R.color.colorGreyIcon)), null, null, null);
}
}
});
}
Run Code Online (Sandbox Code Playgroud)
这是应用程序的屏幕:
Fun*_*nal 13
根据Drawable#setTint(int)上的Android文档:
要清除色调,请
null转到setTintList(ColorStateList).
注意:getDrawable(int)如果您之前已在活动中的相同Drawable Id上设置了色调,则仅调用创建新Drawable不足以清除色调.
请注意,setTintList( null )这只适用于API 21以上(Android 5.0,Lollipop).因此ImageViewCompat建议使用:
ImageViewCompat.setImageTintList( iv,null);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3764 次 |
| 最近记录: |