Here is my code in xml layout:
<TextView
android:id="@+id/mail_message_content_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Medium Text"
android:autoLink="web"
android:drawableLeft="@drawable/attachment"
android:drawablePadding="10dp"
android:gravity="center|left"
android:textAppearance="?android:attr/textAppearanceMedium" />
The same way I want to change drawablePadding for drawable programmatically. How to do this?
This example demonstrates how do I set background drawable programmatically in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.java.
AndroidMobile DevelopmentApps/Applications This example demonstrates how do I programmatically set drawableleft in android. Step 1− Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2− Add the following code to res/layout/activity_main.xml.
I strongly recommend putting your dp padding in dimen xml file and use the official Android conversions to have consistent behaviour with regard to how Android framework works. Show activity on this post.
setCompoundDrawablesWithIntrinsicBounds (int left, int top, int right, int bottom) Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text. Use 0 if you do not want a Drawable there. The Drawables' bounds will be set to their intrinsic bounds.
You can get refernce of ur text view and then can set
UrTextView.setCompoundDrawablePadding(your padding value);
textView.setCompoundDrwablePadding(takes_only_one_argument_for_all_side_padding);
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