android - How to make one border.xml file which can be configured with a color? -


i have many textview in layout each of border different color. know can create border around textview using

<textview     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:background="@drawable/border"/> 

where border.xml follows

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"     android:padding="10dp"     android:shape="rectangle" >      <stroke         android:width="3dp"         android:color="#ff0000" />  </shape> 

but have 8-9 different textviews border 8-9 different border colors. there way without creating 8-9 differert bordercolor.xml (borderpink.xml, borderblue.xml etc) files?

you dynamically, using gradientdrawable , setting in textvew.

there 2 ways, can define drawable on code (use own properties), this:

gradientdrawable drawable = new gradientdrawable();     drawable.setshape(gradientdrawable.rectangle);     drawable.setstroke(5, color.magenta); 

also, can resource border.xml.

resources res = this.getresources(); gradientdrawable drawable  = (gradientdrawable)res.getdrawable(r.drawable.border); 

after that, set textview.

textview.setbackgrounddrawable(drawable); 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -