1
I have a due case that I am using three images for each of my buttons, as shown below the images:
- ic_palette_black_36dp
- ic_palette_red_36dp
- ic_palette_blue_36dp
Code:
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Button"
android:drawableLeft="@drawable/ic_palette_black_36dp"
/>
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Button"
android:drawableLeft="@drawable/ic_palette_red_36dp"
/>
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Button"
android:drawableLeft="@drawable/ic_palette_blue_36dp"
/>
One way to do this, however in Lollipop, Android 5. + is by setting a tone in a drawable bitmap
, in this way:
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/ic_back"
android:tint="@color/red_tint"/>
I’m using Android 2.3.3 Gingerbrend and Eclipse, so I would like to find a solution without using any lib
. It is possible to set a color for the added image with the android:drawableLeft
in these conditions? If anyone can help, thank you!
Speak, my friend, quiet! Well, I forgot to mention that I am looking for a solution for API 10 without having to insert some lib. But just below in the question it appears to work in versions smaller than Lollipop.
– viana
But you don’t need another library. Only Appcompat. Aren’t you using Appcompat? It is practically mandatory to use it if you want to support older versions of the system.
– Pablo Almeida
I work for a company that developed an internal app three/four years ago but I still haven’t convinced them to work with the more modern versions, but I’m working on it. So I didn’t want to add
libs
to make just a few changes etc. The app is not in the Playstore, so I ended up developing a service to check details of the devices being installed. Then I’ll have a static to make some kind of decision.Dude, to tell you the truth, I’ve already solved the problem differently, but I wanted someone to publish something cool so I can give the credit– viana
@Cleidimarviana You’ll have to practically rewrite the Appcompat to do this. I understand your concern to add libraries to little, but that’s no small thing. Appcompat is the standard (official) compatibility library. Without it it is even difficult to support new versions without breaking old ones. It is already included when you create a project in Android Studio, inclusive. To take it out you have to know what is doing. Since the app is not in the store, this is one more reason not to have to worry about the size.
– Pablo Almeida
Anyway, whenever you ask a question like this, make it explicit that you do not want to use Appcompat, to avoid this kind of thing.
– Pablo Almeida
Blz! I just forgot to make it explicit. Thanks for the tip. Here we use Eclipse and we do not use Appcompat. Single
lib
more up-to-date in relation toAndroid developer
issupport-v4.jar
. The other libs are for specific cases. Hugs. Vlw– viana