Home » Android » Add buttons to a jpg image

Add buttons to a jpg image

Posted by: admin November 1, 2017 Leave a comment

Questions:

I would like to use the following image and have 2 invisible buttons where is “Select Colour” and “Select Type“. I know I should use the image as background but my problem is how to add the buttons on the image on those specific locations for every time the user clicks on them, they do open different fragments.

enter image description here

Answers:

Something like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@android:drawable/btn_star_big_off"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:id="@+id/above"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight=".5"
        android:clickable="true"
        android:text="Select color"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight=".5"
        android:clickable="true"
        android:text="Select type"/>
</LinearLayout>

With a result like this:

enter image description here