Questions tagged [compound-drawables]
40 questions
261
votes
41 answers
Handling click events on a drawable within an EditText
I have added an image right of the text in an EditText widget, using the following XML:

Manikandan
- 4,358
- 5
- 19
- 13
218
votes
4 answers
How do I use a compound drawable instead of a LinearLayout that contains an ImageView and a TextView
Ran the new Lint tool against my code. It came up with a lot of good suggestions, but this one I cannot understand.
This tag and its children can be replaced by one and a compound drawable
Issue: Checks whether the current node can be replaced by…

Leo
- 4,652
- 6
- 32
- 42
131
votes
17 answers
Is it possible to use VectorDrawable in Buttons and TextViews using android:DrawableRight?
When I use VectorDrawable assets in a textview or imageview I get a runtime crash when using "android:DrawableRight" / "android:DrawableEnd" / "android:DrawableStart" / "android:DrawableLeft".
The app will compile fine without any warnings.
I am…

angryITguy
- 9,332
- 8
- 54
- 82
88
votes
16 answers
How can I shrink the drawable on a button?
how can I make the drawable on a button smaller? The icon is too big, actually higher than the button. This is the code I am using:
23
votes
3 answers
Set actual text padding in TextView with compound drawables
I have a ListView populated with an ArrayAdapter. For items I use just a single TextView layout. I want some of the rows to have compound drawables set.
Question: is there a way to set padding for the actual text that is contained in TextView so…

Gio
- 1,954
- 3
- 22
- 42
19
votes
2 answers
How to set height and width of compound drawable textview in xml?
I can't see any tag to set width
Here I set textview height, if I set width it will not work properly.

Rafael Oliveira
- 191
- 1
- 5
15
votes
1 answer
How to vertically align text in a TextView with Compound Drawable
This question is in a way a continuation of my last question.
My problem now is pretty much the same, except that instead of separating the image and text in differend views (namely ImageView and TextView) I learned I can use the attribute…

Nick Fanelli
- 265
- 1
- 6
- 19
7
votes
3 answers
Customize AppCompatButton drawableLeft?
How can I place drawableLeft and button text of AppCompatButton like in the image below?
I have tried to apply paddingLeft, but the text is moving away from the drawable to the right.

Stella
- 1,817
- 6
- 30
- 55
6
votes
0 answers
How to place Compound drawable on top left of Text View
We can set compound drawables for textview as below using drawableLeft or setCompundDrawables but using this its only possible to place the drawable on left / right / top / bottom.But i want to put drawables only at top-left and top-right of the…

Bunny Rabbit
- 8,213
- 16
- 66
- 106
6
votes
2 answers
How to align the text with its compound drawables in TextView?
I can't figure out how to set the alignment of text and its compound drawable (smaller than text) in a TextView. It seems the default alignment is center, but I need to align them by the edge.
PS: The android:gravity works great if compound drawable…

Oasis Feng
- 7,490
- 3
- 31
- 44
5
votes
0 answers
Measuring TextView with compound drawable returns wrong value
I want to know a view's size before hand. I measure its size this way.
public static int[] measureSize(ViewGroup parent, int layoutId)
{
View view = LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false);
final int spec =…

Run
- 2,148
- 2
- 12
- 29
5
votes
1 answer
Android Data Binding Null Coalescing Operator
I'm trying to use the null coalescing operator in my data binding. I have a compound drawable that I need to show one of three drawable icons, depending on if the variable is null, true, or false.
The XML

VIN
- 6,385
- 7
- 38
- 77
5
votes
6 answers
Fixed-width TextView with stretched compound drawable
I'm trying to achieve the following layout: a fixed width TextView aligned to the left of its parent, with the text inside it aligned to the right side of that TextView (that's why fixed width, can it be done other way?) and the rest of the parent…

aragaer
- 17,238
- 6
- 47
- 49
3
votes
2 answers
Attempt to invoke virtual method 'android.graphics.Rect android.graphics.drawable.Drawable.getBounds()' on a null object reference
I have the following code:
etEmail.setOnTouchListener((view, motionEvent) -> {
final int DRAWABLE_RIGHT = 2;
if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
if(motionEvent.getRawX() >= (etEmail.getRight() -…

Amos
- 1,321
- 2
- 23
- 44
3
votes
2 answers
show compound drawable to EditText on event
In my application in Activity I want to set EditText as I click inside(focus) EditText and type a key clear button should appear on right side of EditText and when EditText is empty that clear button have to removed.But it is not showing to…

Pravin
- 1,362
- 12
- 21