1

I have a num keypad that I have created using buttons and have hide my android soft keyboard.

This is how my every button looks like for different numbers

 <Button
        android:id="@+id/seven"
        android:text="7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        style="@style/CustomStyle"
        android:background="@drawable/gridlayout_border"
 />

Notice that I am using CustomStyle whose code looks like this with the filename button_style.xml

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="CustomStyle">
        <item name="android:textSize">24dp </item>
        <item name="android:textColor">#fdfdfd</item>
        <item name="android:textStyle">bold </item>
        <item name="android:padding">20dp</item>
    </style>

</resources>

Also, I am using gridlayout_border as a background gridlayout_border.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:left="-10dp" android:right="0dp"  android:top="-10dp"
        >
        <shape android:shape="rectangle">
            <!--apply button background transparent, full opacity-->
            <solid android:color="#00ffffff"/>
            <stroke android:color="#ffffff" android:width="2dp"/>
        </shape>
    </item>
</layer-list>

Since, I have used up the style and background tag in button. How can I now apply one more style/color when my button is being pressed on num keypad?

Thanks in advance

Rajiv Thakur
  • 61
  • 1
  • 5

1 Answers1

0

You can use selector to determine different states of a view. Something like this:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true">
    <!-- Write your focused state code-->
</item>
<item android:state_pressed="true">
    <!-- Write your pressed state code-->
</item>
<item>
    <layer-list>
        <item android:left="-10dp" android:right="0dp" android:top="-10dp"
            >
            <shape android:shape="rectangle">
                <!--apply button background transparent, full opacity-->
                <solid android:color="#00ffffff"/>
                <stroke android:width="2dp" android:color="#ffffff"/>
            </shape>
        </item>
    </layer-list>
</item>
</selector>
Srijith
  • 1,695
  • 17
  • 29
  • i tired your above code as it is, getting binary xml error like Binary XML file line #202: Error inflating class Button and File res/drawable/gridlayout_border.xml from drawable resource ID #0x7f020048 – Rajiv Thakur Mar 08 '16 at 08:30