I have a button with drawable left:
<Button
android:id="@+id/post_feeling_btn"
android:background="@color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp"
android:drawableLeft="@drawable/feeling_btn"
android:gravity="left|center_vertical"
android:textColor="@color/gray"
android:text="Sentimento"/>
In my on resume method, I change the button's text programmatically:
Button setFeeling;
FeelingButton selectedFeeling;
@Override
public void onResume() {
super.onResume();
selectedFeeling = ((FeedActivity)getActivity()).getSelectedFeeling();
if(selectedFeeling != null){
setFeeling.setText(selectedFeeling.getFeeling());
}
}
Is there a way to change my drawable left and set the image in the same method, using the image I have in my selectedFeeling object? I'm looking for something like:
setFeeling.setDrawable();
try something like this: for drawableLeft
int imgResource = R.drawable.your_drawable;
setFeeling.setCompoundDrawablesWithIntrinsicBounds(imgResource, 0, 0, 0);
setFeeling.setCompoundDrawablePadding(8); //for padding
Thanks to the Answer Here also.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With