Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to set drawablePadding programmatically?

Tags:

android

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?

like image 216
zarej Avatar asked Feb 20 '13 11:02

zarej


People also ask

How to set background drawable programmatically in Android?

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.

How to programmatically set drawableleft in Android?

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.

Where to put DP padding in Android framework?

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.

How do I set drawables to their intrinsic bounds?

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.


2 Answers

You can get refernce of ur text view and then can set

UrTextView.setCompoundDrawablePadding(your padding value);
like image 50
user1969053 Avatar answered Oct 21 '22 22:10

user1969053


textView.setCompoundDrwablePadding(takes_only_one_argument_for_all_side_padding); 
like image 45
Sumitkush1419 Avatar answered Oct 21 '22 21:10

Sumitkush1419