I've defined a layout in XML and now I'd like to use it to make a custom button (It just has to show the layout and be clickable, I don't care about different states and stuff). I'm not too sure what to do next though. How to I create this in my main activity?
Thanks!
My custom XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:textSize="20dp"
android:text="New Text"
android:id="@+id/text" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginRight="25dp"
android:layout_alignParentRight="true"
android:src="@drawable/left"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:maxHeight="30dp"
android:maxWidth="30dp"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
android:height="1dp"
android:background="@color/dim_foreground_material_dark"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:text=""
android:id="@+id/horiz" />
</RelativeLayout>
findViewById()method. Then attach an onclick event to the object.