xml - How to add the border on editext programmatically in android -
i working on demo app require set the border width , border color programmatically.
i know can done using xml drawable want these @ run time. know have these creating xml , use requirement such dynamic have these stuff @ runtime instead of below approach.
border_edittext.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <solid android:color="#ffffff" /> <stroke android:width="1dip" android:color="#000000"/> </shape>
setting drawable.
edittext foo = (edittext)findviewbyid(r.id.edittext); foo.setbackgroundresource(r.drawable.border_edittext);
thanks in advance.
shape drawables
came mind first. android guide has details on this.
int x = 10; int y = 10; int width = 300; int height = 50; mdrawable = new shapedrawable(new rectshape()); // rectangle border mdrawable.getpaint().setcolor(0xff74ac23); // set color mdrawable.setbounds(x, y, x + width, y + height); setcontentview(mdrawable);
but wouldn't hollow rectangle, you'd want border. see this answer more discussion using border. tricky part getting transparency. looks have settled drawing 4 lines around border of canvas.
a canvas can created this.
bitmap b = bitmap.createbitmap(100, 100, bitmap.config.argb_8888); canvas c = new canvas(b);
Comments
Post a Comment