Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8575171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:38:04+00:00 2026-06-11T19:38:04+00:00

I’m facing problem in putting cross button on top of the textview. I’m using

  • 0

I’m facing problem in putting cross button on top of the textview. I’m using LinearLayout and it is not coming up on that, whereas on Framelayout it work but that does not solve my purpose. I’m attaching my XML for reference, please help me in overcoming this problem.

<LinearLayout
        android:id="@+id/top"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/phone_toolbar"
        android:baselineAligned="true"
        android:gravity="center_horizontal"
        android:paddingBottom="2dp"
        android:paddingTop="2dp" >

        <ImageView
            android:id="@+id/search_icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="10dp"
            android:background="@drawable/toolbar_search_icon_phone" >
        </ImageView>

        <AutoCompleteTextView
            android:id="@+id/text"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginRight="10dp"
            android:layout_weight="2"
            android:background="@drawable/toolbar_phone_textfield"
            android:dropDownVerticalOffset="5dp"
            android:ems="10"
            android:focusable="true"
            android:hint="@string/hint"
            android:imeOptions="actionSearch"
            android:paddingLeft="10dp"
            android:paddingRight="20dp"
            android:singleLine="true"
            android:textColor="#000000"
            android:textSize="14sp" />

        <Button
            android:id="@+id/clear_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right|center_vertical"
            android:layout_marginRight="10dip"
            android:background="@drawable/text_clear" />
    </LinearLayout>

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:38:05+00:00Added an answer on June 11, 2026 at 7:38 pm

    Use the android:drawableLeft property on the EditText.

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

    if you want to add the icon dynamically, use this:

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

    To handle the click events:

    String value = "";//any text you are 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 standard 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() {
        @Override
        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() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            et.setCompoundDrawables(null, null, et.getText().toString().equals("") ? null : x, null);
        }
    
        @Override
        public void afterTextChanged(Editable arg0) {
        }
    
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }
    });
    

    and this can also be done using a custom EditText:

    Handling click events on a drawable within an EditText

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.