9 ответов:
вы можете использовать функцию ниже:
editText.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.drawableRight, 0);порядок параметров, соответствующих отображаемому местоположению: слева, сверху, справа, снизу
Найти здесь
EditText myEdit = (EditText) findViewById(R.id.myEdit); myEdit.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.icon, 0); // where params are (left,top,right,bottom)вы также можете установить drawable padding программно:
myEdit.setCompoundDrawablePadding("Padding value");
попробовать, как показано ниже:
Drawable img = getContext().getResources().getDrawable( R.drawable.smiley ); EdtText.setCompoundDrawablesWithIntrinsicBounds( 0, 0, img, 0);Edit:
int img = R.drawable.smiley; EdtText.setCompoundDrawablesWithIntrinsicBounds( 0, 0, img, 0);
int img = R.drawable.smiley; editText.setCompoundDrawables( null, null, img, null );объяснил здесь
setCompoundDrawablesWithIntrinsicBounds (int left, int top, int right, int bottom)устанавливает чертежи (если таковые имеются) для отображения слева, сверху, справа и ниже текста. Используйте 0, если вы не хотите рисовать там. Границы чертежей будут установлены на их внутренние границы.
попробуй:
EditText editFirstname = (EditText) findViewById(R.id.edit_fname); Drawable icUser = getResources().getDrawable(R.drawable.ic_user); editFirstname.setCompoundDrawablesWithIntrinsicBounds(null, null, icUser, null);затем вы можете добавить сенсорный прослушиватель к этому конкретному drawable.
вы можете использовать свой вид editText (здесь это txview) встроенный в функцию setCompoundDrawablesWithIntrinsicbounds (), чтобы сделать то, что вы ищете
в моем коде я использовал его так . txview.setCompoundDrawablesWithIntrinsicbounds (0,0,R. drawable.ic_arrow_drop_up,0);
txview.setCompoundDrawablesWithIntrinsicBounds(left,top,right,bottom);
et_feedback.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { } et_feedback.setCompoundDrawablesWithIntrinsicBounds(0,R.mipmap.feedback_new, 0, 0); et_feedback.setTextColor(Color.BLACK); } });скрыть Drawable с помощью этого
et_feedback.setCompoundDrawablesWithIntrinsicBounds(0,0, 0, 0);
для изменения влево и вправо и одновременно я использую эту одну строку.
download.setCompoundDrawablesWithIntrinsicBounds( R.drawable.ic_lock_open_white_24dp, 0, R.drawable.ic_lock_open_white_24dp, 0);
Если это требует android графики drawable, то это будет работать
Drawable dw = getApplicationContext().getResources().getDrawable(R.drawable.edit); Button start = (Button)findViewById(R.id.buttonStart); start.setCompoundDrawablesWithIntrinsicBounds(dw, null, null, null);
Comments