Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>i have the solution for you</p> <ul> <li>wrap the <code>ImageButton</code> and 'TextView' in a 'LinearLayout' </li> <li>Disable the <code>clickable</code>, <code>focusable</code> events of Imagebutton and textview</li> <li>Apply a custom selector for your <code>LinearLayout</code></li> </ul> <p>here goes the updated <code>custom_component.xml</code> layout file</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/toast_layout_root" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#f0f0f0" android:gravity="center" android:orientation="horizontal" android:padding="10dp" &gt; &lt;LinearLayout android:id="@+id/myCustomComponent" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="@drawable/layout_bgimage_selector" android:clickable="true" android:focusable="true" android:focusableInTouchMode="true" android:gravity="center" android:orientation="vertical" &gt; &lt;ImageButton android:id="@+id/testImage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:clickable="false" android:focusable="false" android:focusableInTouchMode="false" android:src="@drawable/icon" /&gt; &lt;TextView android:id="@+id/testText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:clickable="false" android:focusable="false" android:focusableInTouchMode="false" android:text="Test Text" android:textColor="#FFF" /&gt; &lt;/LinearLayout&gt; &lt;/RelativeLayout&gt; </code></pre> <p>this layout file uses custom selector xml file <code>layout_bgimage_selector.xml</code>, which needs to be placed in <code>res/drawable</code> folder</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:drawable="@drawable/background" android:state_enabled="false"/&gt; &lt;item android:drawable="@drawable/background" android:state_focused="true" android:state_pressed="true"/&gt; &lt;item android:drawable="@drawable/background_over" android:state_enabled="true" android:state_pressed="true"/&gt; &lt;item android:drawable="@drawable/background_over" android:state_enabled="true" android:state_focused="true"/&gt; &lt;item android:drawable="@drawable/background" android:state_enabled="true"/&gt; &lt;/selector&gt; </code></pre> <p>the 9-patch images i used for layout selector are :</p> <p>background.9.png - <img src="https://i.stack.imgur.com/Nrv8L.png" alt="background.9.png"></p> <p>background_over.9.png - <img src="https://i.stack.imgur.com/KeE6y.png" alt="background_over.9.png"></p> <p>place them in <code>res/drawable-hdpi</code> folder. (or any image resource folder that matches your device configs)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload