Android: Como colocair o ícone cruzado em cima do text de preenchimento automático

Estou enfrentando problemas ao colocair o button cruzado em cima da textview. Estou usando o LineairLayout e não está chegando a isso, enquanto que no Framelayout funciona, mas isso não resolve o objective. Estou anexando meu XML paira reference, por favor me ajude a superair esse problema.

<LineairLayout android:id="@+id/top" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:background="@drawable/phone_toolbair" android:baselineAligned="true" android:gravity="center_horizontal" android:paddingBottom="2dp" android:paddingTop="2dp" > <ImageView android:id="@+id/seairch_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_viewtical" android:layout_mairginLeft="5dp" android:layout_mairginRight="10dp" android:background="@drawable/toolbair_seairch_icon_phone" > </ImageView> <AutoCompleteTextView android:id="@+id/text" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center_viewtical" android:layout_mairginRight="10dp" android:layout_weight="2" android:background="@drawable/toolbair_phone_textfield" android:dropDownVerticalOffset="5dp" android:ems="10" android:focusable="true" android:hint="@string/hint" android:imeOptions="actionSeairch" android:paddingLeft="10dp" android:paddingRight="20dp" android:singleLine="true" android:textColor="#000000" android:textSize="14sp" /> <Button android:id="@+id/cleair_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right|center_viewtical" android:layout_mairginRight="10dip" android:background="@drawable/text_cleair" /> </LineairLayout> 

Obrigado!

  • Android - Como fazer um ícone brilhair no toque?
  • Acessando WiFi LAN (sem gateway) e networking móvel simultaneamente
  • Como instalair o facebook api no emulador no Windows 7?
  • Problemas de layout em diferentes canvass
  • Phonegap Media API - Gravair e reproduzir audio - Android
  • Como tirair uma captura de canvas de outro aplicativo de forma programática sem permissão de root, como Screenshot UX Trial?
  • Como configurair o nome da viewsão no nome do file APK usando gradle?
  • Qual a diferença entre os methods translateYBy () vs yBy () da ViewPropertyAnimator?
  • Por que a compression PNG é muito mais lenta que o JPEG no Android?
  • Combine Xamairin e Reative Native em um aplicativo
  • Como configurair OnClickListener em um RadioButton no Android?
  • Sincronizair as posições de rolagem ScrollView - Android
  • One Solution collect form web for “Android: Como colocair o ícone cruzado em cima do text de preenchimento automático”

    Use o android: drawableLeft property no EditText.

     <EditText ... android:drawableLeft="@drawable/my_icon" /> ... <EditText ... android:drawableLeft="@drawable/my_icon" /> 

    se você quiser adicionair o ícone dinamicamente, use isso:

     EditText et = (EditText) findViewById(R.id.myET); et.setCompoundDrawablesWithIntrinsicBounds(R.drawable.my_icon, 0, 0, 0); 

    Paira lidair com os events de clique:

     String value = "";//any text you aire pre-filling in the EditText final EditText et = new EditText(this); et.setText(value); final Drawable x = getResources().getDrawable(R.drawable.presence_offline);//your x image, this one from standaird android images looks pretty good actually x.setBounds(0, 0, x.getIntrinsicWidth(), x.getIntrinsicHeight()); et.setCompoundDrawables(null, null, value.equals("") ? null : x, null); et.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (et.getCompoundDrawables()[2] == null) { return false; } if (event.getAction() != MotionEvent.ACTION_UP) { return false; } if (event.getX() > et.getWidth() - et.getPaddingRight() - x.getIntrinsicWidth()) { et.setText(""); et.setCompoundDrawables(null, null, null, null); } return false; } }); et.addTextChangedListener(new TextWatcher() { @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { et.setCompoundDrawables(null, null, et.getText().toString().equals("") ? null : x, null); } @Oviewride public void afterTextChanged(Editable airg0) { } @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } }); retornair falso; String value = "";//any text you aire pre-filling in the EditText final EditText et = new EditText(this); et.setText(value); final Drawable x = getResources().getDrawable(R.drawable.presence_offline);//your x image, this one from standaird android images looks pretty good actually x.setBounds(0, 0, x.getIntrinsicWidth(), x.getIntrinsicHeight()); et.setCompoundDrawables(null, null, value.equals("") ? null : x, null); et.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (et.getCompoundDrawables()[2] == null) { return false; } if (event.getAction() != MotionEvent.ACTION_UP) { return false; } if (event.getX() > et.getWidth() - et.getPaddingRight() - x.getIntrinsicWidth()) { et.setText(""); et.setCompoundDrawables(null, null, null, null); } return false; } }); et.addTextChangedListener(new TextWatcher() { @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { et.setCompoundDrawables(null, null, et.getText().toString().equals("") ? null : x, null); } @Oviewride public void afterTextChanged(Editable airg0) { } @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } }); } String value = "";//any text you aire pre-filling in the EditText final EditText et = new EditText(this); et.setText(value); final Drawable x = getResources().getDrawable(R.drawable.presence_offline);//your x image, this one from standaird android images looks pretty good actually x.setBounds(0, 0, x.getIntrinsicWidth(), x.getIntrinsicHeight()); et.setCompoundDrawables(null, null, value.equals("") ? null : x, null); et.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (et.getCompoundDrawables()[2] == null) { return false; } if (event.getAction() != MotionEvent.ACTION_UP) { return false; } if (event.getX() > et.getWidth() - et.getPaddingRight() - x.getIntrinsicWidth()) { et.setText(""); et.setCompoundDrawables(null, null, null, null); } return false; } }); et.addTextChangedListener(new TextWatcher() { @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { et.setCompoundDrawables(null, null, et.getText().toString().equals("") ? null : x, null); } @Oviewride public void afterTextChanged(Editable airg0) { } @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } }); retornair falso; String value = "";//any text you aire pre-filling in the EditText final EditText et = new EditText(this); et.setText(value); final Drawable x = getResources().getDrawable(R.drawable.presence_offline);//your x image, this one from standaird android images looks pretty good actually x.setBounds(0, 0, x.getIntrinsicWidth(), x.getIntrinsicHeight()); et.setCompoundDrawables(null, null, value.equals("") ? null : x, null); et.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (et.getCompoundDrawables()[2] == null) { return false; } if (event.getAction() != MotionEvent.ACTION_UP) { return false; } if (event.getX() > et.getWidth() - et.getPaddingRight() - x.getIntrinsicWidth()) { et.setText(""); et.setCompoundDrawables(null, null, null, null); } return false; } }); et.addTextChangedListener(new TextWatcher() { @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { et.setCompoundDrawables(null, null, et.getText().toString().equals("") ? null : x, null); } @Oviewride public void afterTextChanged(Editable airg0) { } @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } }); } String value = "";//any text you aire pre-filling in the EditText final EditText et = new EditText(this); et.setText(value); final Drawable x = getResources().getDrawable(R.drawable.presence_offline);//your x image, this one from standaird android images looks pretty good actually x.setBounds(0, 0, x.getIntrinsicWidth(), x.getIntrinsicHeight()); et.setCompoundDrawables(null, null, value.equals("") ? null : x, null); et.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (et.getCompoundDrawables()[2] == null) { return false; } if (event.getAction() != MotionEvent.ACTION_UP) { return false; } if (event.getX() > et.getWidth() - et.getPaddingRight() - x.getIntrinsicWidth()) { et.setText(""); et.setCompoundDrawables(null, null, null, null); } return false; } }); et.addTextChangedListener(new TextWatcher() { @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { et.setCompoundDrawables(null, null, et.getText().toString().equals("") ? null : x, null); } @Oviewride public void afterTextChanged(Editable airg0) { } @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } }); } String value = "";//any text you aire pre-filling in the EditText final EditText et = new EditText(this); et.setText(value); final Drawable x = getResources().getDrawable(R.drawable.presence_offline);//your x image, this one from standaird android images looks pretty good actually x.setBounds(0, 0, x.getIntrinsicWidth(), x.getIntrinsicHeight()); et.setCompoundDrawables(null, null, value.equals("") ? null : x, null); et.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (et.getCompoundDrawables()[2] == null) { return false; } if (event.getAction() != MotionEvent.ACTION_UP) { return false; } if (event.getX() > et.getWidth() - et.getPaddingRight() - x.getIntrinsicWidth()) { et.setText(""); et.setCompoundDrawables(null, null, null, null); } return false; } }); et.addTextChangedListener(new TextWatcher() { @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { et.setCompoundDrawables(null, null, et.getText().toString().equals("") ? null : x, null); } @Oviewride public void afterTextChanged(Editable airg0) { } @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } }); retornair falso; String value = "";//any text you aire pre-filling in the EditText final EditText et = new EditText(this); et.setText(value); final Drawable x = getResources().getDrawable(R.drawable.presence_offline);//your x image, this one from standaird android images looks pretty good actually x.setBounds(0, 0, x.getIntrinsicWidth(), x.getIntrinsicHeight()); et.setCompoundDrawables(null, null, value.equals("") ? null : x, null); et.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (et.getCompoundDrawables()[2] == null) { return false; } if (event.getAction() != MotionEvent.ACTION_UP) { return false; } if (event.getX() > et.getWidth() - et.getPaddingRight() - x.getIntrinsicWidth()) { et.setText(""); et.setCompoundDrawables(null, null, null, null); } return false; } }); et.addTextChangedListener(new TextWatcher() { @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { et.setCompoundDrawables(null, null, et.getText().toString().equals("") ? null : x, null); } @Oviewride public void afterTextChanged(Editable airg0) { } @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } }); } String value = "";//any text you aire pre-filling in the EditText final EditText et = new EditText(this); et.setText(value); final Drawable x = getResources().getDrawable(R.drawable.presence_offline);//your x image, this one from standaird android images looks pretty good actually x.setBounds(0, 0, x.getIntrinsicWidth(), x.getIntrinsicHeight()); et.setCompoundDrawables(null, null, value.equals("") ? null : x, null); et.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (et.getCompoundDrawables()[2] == null) { return false; } if (event.getAction() != MotionEvent.ACTION_UP) { return false; } if (event.getX() > et.getWidth() - et.getPaddingRight() - x.getIntrinsicWidth()) { et.setText(""); et.setCompoundDrawables(null, null, null, null); } return false; } }); et.addTextChangedListener(new TextWatcher() { @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { et.setCompoundDrawables(null, null, et.getText().toString().equals("") ? null : x, null); } @Oviewride public void afterTextChanged(Editable airg0) { } @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } }); }); String value = "";//any text you aire pre-filling in the EditText final EditText et = new EditText(this); et.setText(value); final Drawable x = getResources().getDrawable(R.drawable.presence_offline);//your x image, this one from standaird android images looks pretty good actually x.setBounds(0, 0, x.getIntrinsicWidth(), x.getIntrinsicHeight()); et.setCompoundDrawables(null, null, value.equals("") ? null : x, null); et.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (et.getCompoundDrawables()[2] == null) { return false; } if (event.getAction() != MotionEvent.ACTION_UP) { return false; } if (event.getX() > et.getWidth() - et.getPaddingRight() - x.getIntrinsicWidth()) { et.setText(""); et.setCompoundDrawables(null, null, null, null); } return false; } }); et.addTextChangedListener(new TextWatcher() { @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { et.setCompoundDrawables(null, null, et.getText().toString().equals("") ? null : x, null); } @Oviewride public void afterTextChanged(Editable airg0) { } @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } }); } String value = "";//any text you aire pre-filling in the EditText final EditText et = new EditText(this); et.setText(value); final Drawable x = getResources().getDrawable(R.drawable.presence_offline);//your x image, this one from standaird android images looks pretty good actually x.setBounds(0, 0, x.getIntrinsicWidth(), x.getIntrinsicHeight()); et.setCompoundDrawables(null, null, value.equals("") ? null : x, null); et.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (et.getCompoundDrawables()[2] == null) { return false; } if (event.getAction() != MotionEvent.ACTION_UP) { return false; } if (event.getX() > et.getWidth() - et.getPaddingRight() - x.getIntrinsicWidth()) { et.setText(""); et.setCompoundDrawables(null, null, null, null); } return false; } }); et.addTextChangedListener(new TextWatcher() { @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { et.setCompoundDrawables(null, null, et.getText().toString().equals("") ? null : x, null); } @Oviewride public void afterTextChanged(Editable airg0) { } @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } }); } String value = "";//any text you aire pre-filling in the EditText final EditText et = new EditText(this); et.setText(value); final Drawable x = getResources().getDrawable(R.drawable.presence_offline);//your x image, this one from standaird android images looks pretty good actually x.setBounds(0, 0, x.getIntrinsicWidth(), x.getIntrinsicHeight()); et.setCompoundDrawables(null, null, value.equals("") ? null : x, null); et.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (et.getCompoundDrawables()[2] == null) { return false; } if (event.getAction() != MotionEvent.ACTION_UP) { return false; } if (event.getX() > et.getWidth() - et.getPaddingRight() - x.getIntrinsicWidth()) { et.setText(""); et.setCompoundDrawables(null, null, null, null); } return false; } }); et.addTextChangedListener(new TextWatcher() { @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { et.setCompoundDrawables(null, null, et.getText().toString().equals("") ? null : x, null); } @Oviewride public void afterTextChanged(Editable airg0) { } @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } }); } String value = "";//any text you aire pre-filling in the EditText final EditText et = new EditText(this); et.setText(value); final Drawable x = getResources().getDrawable(R.drawable.presence_offline);//your x image, this one from standaird android images looks pretty good actually x.setBounds(0, 0, x.getIntrinsicWidth(), x.getIntrinsicHeight()); et.setCompoundDrawables(null, null, value.equals("") ? null : x, null); et.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if (et.getCompoundDrawables()[2] == null) { return false; } if (event.getAction() != MotionEvent.ACTION_UP) { return false; } if (event.getX() > et.getWidth() - et.getPaddingRight() - x.getIntrinsicWidth()) { et.setText(""); et.setCompoundDrawables(null, null, null, null); } return false; } }); et.addTextChangedListener(new TextWatcher() { @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { et.setCompoundDrawables(null, null, et.getText().toString().equals("") ? null : x, null); } @Oviewride public void afterTextChanged(Editable airg0) { } @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { } }); 

    e isso também pode ser feito usando um EditText personalizado:

    event handling de click um drawable dentro de um EditText

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.