Showing posts with label Set Drawable at Run time. Show all posts
Showing posts with label Set Drawable at Run time. Show all posts

Saturday, 22 April 2017

Set Drawable at Run time

If you want change drawableLeft/Right/Top/Bottom property of view at run time then use following method
  •  setCompoundDrawablesWithIntrinsicBounds(int left,int top,int right,int bottom)
 Note: When we are setting this property layout padding and drawable padding are reset  so we need to set padding again.
  • setPadding(int left, int top, int right, int bottom) :  Set layout padding
  • setCompoundDrawablePadding: Set drawable padding
Example : In following example we have set drawableLeft property to EditText and DrawableRight property to TextView

     editTextDrawableLeft = (EditText)findViewById(R.id.editText_drawable_left);  
     textViewDrawableRight =(TextView)findViewById(R.id.textView_drawable_right);  
   
     //here we are setting image to left side of editText  
     editTextDrawableLeft.setCompoundDrawablesWithIntrinsicBounds(R.drawable.user_profile,0,0,0);  
     //now set the padding and drawable to editText  
     editTextDrawableLeft.setPadding(10,10,10,10);  
     editTextDrawableLeft.setCompoundDrawablePadding(20);  
   
     //now set the drable to textView  
     textViewDrawableRight.setCompoundDrawablesWithIntrinsicBounds(0,0,R.drawable.user_profile,0);  
     textViewDrawableRight.setPadding(10,10,10,10);  
     textViewDrawableRight.setCompoundDrawablePadding(20)  

Download Complete Example  

Screen Shot :



Create File on External Storage using Storage access framework for android 10

How To Create File on External Storage on android 10 using Storage Access Framework? By default, apps targeting Android 10 and higher a...