Mohammed Jinas
Mohammed Jinas

Reputation: 11

How to add a color fill for a linear layout onclick?

enter image description here

I am trying to change the color of the buttons and give a gray color fill sliding in from the left towards the right end of the button when clicked before the next acitivity slides in. The buttons are Linear Layouts.

Here is the XML code for the Linear Layouts :

<LinearLayout
        android:id="@+id/stockbtn"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="25sp"
        android:layout_marginRight="25sp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="StockButtonClick"
        android:orientation="horizontal"
        android:clickable="true"
        android:background = "@drawable/roundedbutton">
        <ImageView
            android:src="@drawable/warehouse"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:clickable="false"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="25dp"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="16dp"
            android:layout_weight="70"
            android:clickable="false"
            android:text="STOCK"
            android:textColor="@color/gray"
            android:textSize="18dp"
            android:textStyle="bold" />
    </LinearLayout>
    <LinearLayout
        android:id="@+id/purchasebtn"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="25sp"
        android:layout_marginRight="25sp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="purchaseButtonClick"
        android:orientation="horizontal"
        android:clickable="true"
        android:background = "@drawable/roundedbutton">
        <ImageView
            android:src="@drawable/online_pharmacy"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:clickable="false"/>

        <TextView
            android:id="@+id/purchaseText"
            android:layout_width="0dp"
            android:layout_height="25dp"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="16dp"
            android:layout_weight="70"
            android:clickable="false"
            android:text="PURCHASE"
            android:textColor="@color/gray"
            android:textSize="18dp"
            android:textStyle="bold" />
    </LinearLayout>
    <LinearLayout
        android:id="@+id/debitnotebtn"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="25sp"
        android:layout_marginRight="25sp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="debitnoteButtonClick"
        android:orientation="horizontal"
        android:clickable="true"
        android:background = "@drawable/roundedbutton">
        <ImageView
            android:src="@drawable/payment_method"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:clickable="false"/>

        <TextView

            android:layout_width="0dp"
            android:layout_height="25dp"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="16dp"
            android:layout_weight="70"
            android:clickable="false"
            android:text="DEBIT NOTE"
            android:textColor="@color/gray"
            android:textSize="18dp"
            android:textStyle="bold" />
    </LinearLayout>
    <LinearLayout
        android:id="@+id/itemcheck"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="25sp"
        android:layout_marginRight="25sp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="itemcheckButtonClick"
        android:orientation="horizontal"
        android:clickable="true"
        android:background = "@drawable/roundedbutton">
        <ImageView
            android:src="@drawable/laptop"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:clickable="false"/>

        <TextView

            android:layout_width="0dp"
            android:layout_height="25dp"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="16dp"
            android:layout_weight="70"
            android:clickable="false"
            android:text="ITEM CHECK"
            android:textColor="@color/gray"
            android:textSize="18dp"
            android:textStyle="bold" />
    </LinearLayout>

How do I do this animation or color fill, I don't know what it is called?

Upvotes: 0

Views: 50

Answers (0)

Related Questions