java - Button background with image, text and colour in android -
i want create button background color, icon , text in android. don't know how add image. xml is:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="12dp" android:orientation="vertical" > <tablelayout android:id="@+id/tablelayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="5dp" > <button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/button" android:text="boton" /> </tablelayout> </linearlayout>
and background:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item > <shape android:shape="rectangle" > <corners android:radius="6dip" /> <stroke android:width="1dip" android:color="#5e7974" /> <gradient android:angle="-90" android:startcolor="#345953" android:endcolor="#689a92" /> </shape> </item> </selector>
i want make this:
how add background image plus text in background button? tried put icon property android:drawableleft size little size of button...
this isn't hard. had own project.
android button
s have drawablelocation
property in xml.
to put image @ top, want it, you'd use
android:drawabletop="@drawable/your_drawable_icon"
all 4 possible options are:
android:drawableleft android:drawableright android:drawablebottom android:drawabletop
to adjust spacing/padding of image icon, can use
android:drawablepadding="12dp"
you can read more here.
if isn't accurate enough you, can use relativelayout , put stuff in right.
i had current project. instead of button, had xml:
<relativelayout android:layout_width="match_parent" android:layout_height="60dp" android:id="@+id/applianceinfolayout" android:clickable="true" android:background="@drawable/button_background" > <imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:clickable="false" android:layout_centervertical="true" android:layout_marginleft="@dimen/service_menu_icon_padding" android:layout_marginright="@dimen/service_menu_icon_padding" android:id="@+id/infotextview" android:src="@drawable/ic_applianceinfo"/> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:clickable="false" android:layout_centervertical="true" android:text="info" android:textcolor="#e6e7e8" android:fontfamily="sans-serif-light" android:textallcaps="false" android:textsize="22sp" android:layout_torightof="@id/infotextview"/> </relativelayout>
which gave me this: