Handling click on EditText's rightDrawable image - android

I'm implementing a custom search bar in my Android application. This search bar is just an EditText with a magnifier set to leftDrawable property. My problem is that I don't know how to get noticed when the user clicks the magnifier. Is there any listener for doing this? Am I using the recommended approach to implement this search bar? I know I could use an EditText and an ImageButton on its right side, but I want the magnifier to be inside the EditText.

Is there any listener for doing this?
Not specifically for that image.
Am I using the recommended approach to implement this search bar?
I am not aware that there are recommendations for implementing a search bar. It is not the way Google elected to implement a clickable button for their search bar, which has the button to the right of the field.
You may be able to have the desired effect by:
Putting the EditText in a RelativeLayout
Adding a transparent View as a later child of the EditText, sized to match the size of your image
Using margins to have the transparent View be over top of your image
Setting an OnClickListener on the transparent View

Related

Progress Indicator inside Button on click

Is there a way to set a progress indicator inside a button (preferably using the native Material Button from Material Components - Android)? There is a video on the website showing exactly what I need, but there's nothing in the documentation about it. Here is a screenshot of the same. Wanted to use it on a login button.
I also though of using a CircularProgressDrawable, which I've used before on a chip (as a chip icon), but in case of a button, I don't think there's a way to centre an icon horizontally on a button (my button width matches parent).
If anyone knows how to do this via either of the two ways, I'd be thankful.

How can I make the EditText expandable and hide icons when it is clicked in Android?

I am making a messaging app and wanted a textfield to look like this:
And when the editText is clicked, it will look like this:
And when you clicked "+" it will again show the camera and gallery icon. Similar to Facebook Messenger mobile app's chat text.
How can I make something like this in my layout?
Simplest way to do it is adding setOnFocusChangeListener on your EditText, and in that listener you have to change the Visibility of icons to View.GONE. Analogically with clearing the text/changing focus you have to change the visibility to View.VISIBLE. It will scale nice and easy if you're using ConstraintLayout. Hope it helps, happy coding!
You can try to use ExpandableLayout and customize it so it shows upwards instead of the downward direction it always expands to.

Android ImageButton - How to hide the image while showing the background?

I've read the API and Googled but perhaps I've missed something: All the visibility options on an ImageButton seem to talk about this view as a whole. So, what should I do if I want to hide the image but keep the background(except for explicitly setting the image to something transparent that is)? I'm doing a Pairs Game and when one clicks on the element it should show the image and if the next click doesn't match the image should be hidden, but the grey background of the button should remain.
Thanks!
So, what should I do if I want to hide the image
Try setting it to #null or create transparent PNG in your drawables and set it.
in XML, remove android:src="something" and in the code remove imgbtn.setImageBitmap(null);
Instead of using ImageButton you can use ImageView with a FrameLayout on top of it. Set the background of FrameLayout as gray color and then show/hide this FrameLayout/Image as per your requirement. Take relative layout for each and make it clickable. On the click event of this layout, do the changes as required.

Android Menu Shown Where User Clicked

I wanted to achieve the same sort of functionality found in Google Now where you can tap the cards overflow icon and a menu appears next to it with options (shown here).
Does anyone know how to implement this sort thing to achieve the same style etc?
I think you can do this by placing a listview under your button, and set its visibility to invisible.
Then place an onclicklistener on your button to turn your visibility to visible.

Android: How to do create custom EditText with a clickable arrow on the right

I would like to have an EditText with one modification: on the right but still inside the EditText there should an arrow pointing downwards that I can set OnClickListener to so that when the user clicks on the arrow it displays a menu.
What is the best way to do this?
Do you mean something like this ?
see image
Add the arrow by setting the drawable right attribute
android:drawableRight="#drawable/right"
to your EditText. Then you would need to set an OnTouchListener to get the events.
I did this by putting EditText and a Button into RelativeLayout, the Button (which has custom background drawable) is overlapping the EditBox.
When user clicks on it, the EditBox doesn't receive the click event.
Sounds like a combo box. If you look at the "Building Custom Components" section of the Dev Guide, they mention combo box briefly, but give details on how to build any custom component.

Categories

Resources