Android, setting background color of button loses ripple effect -


after adding color android button, loses ripple effect makes user feel there responsive click. how fix this? i've searched through many solutions couldn't find definite 1 wasn't ambiguous.

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"                 xmlns:tools="http://schemas.android.com/tools"                 android:layout_width="match_parent"                 android:layout_height="match_parent"                 tools:context=".clockinoutfragment">       <analogclock         android:id="@+id/clock"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentend="true"         android:layout_alignparentright="true"         android:layout_alignparenttop="true"         android:layout_torightof="@+id/date_and_time"/>       <relativelayout         android:id="@+id/date_and_time"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_margin="10dp">          <textview             android:id="@+id/time_digits"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="12:10"             android:textsize="45sp"/>          <textview             android:id="@+id/am_pm"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_alignbaseline="@+id/time_digits"             android:layout_torightof="@+id/time_digits"             android:paddingleft="3dp"             android:text="pm"             android:textsize="20sp"/>          <textview             android:id="@+id/date"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_below="@+id/time_digits"             android:text="mon, july 11"             android:textsize="22sp"/>     </relativelayout>      <!--clock in , out buttons-->     <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_alignparentbottom="true"         android:layout_centerhorizontal="true"         android:orientation="horizontal">          <button             android:id="@+id/textview3"             android:layout_width="0dp"             android:layout_height="56dp"             android:layout_weight="1"             android:background="#4caf50"             android:gravity="center"             android:text="clock in"             android:textappearance="?android:attr/textappearancelarge"             android:textcolor="#ffffff"/>          <!--divider between clock in , out button-->         <view             android:layout_width="1dp"             android:layout_height="match_parent"             android:background="#b6b6b6"/>          <button             android:id="@+id/textview4"             android:layout_width="0dp"             android:layout_height="56dp"             android:layout_weight="1"             android:background="#ff5252"             android:gravity="center"             android:text="clock out"             android:textappearance="?android:attr/textappearancelarge"             android:textcolor="#ffffff"/>     </linearlayout>   </relativelayout> 

you can add ripple effect & background color additionnal ripple drawable:

your layout :

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical" android:layout_width="match_parent"     android:layout_height="match_parent">      <button         android:id="@+id/button_connect"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_margintop="20dip"         android:fontfamily="sans-serif"         android:text="connect"         android:background="@drawable/ripple"         android:textcolor="#ffffff"         android:textsize="18sp" />  </linearlayout> 

ripple.xml (this can add background color in addition ripple effect) :

<?xml version="1.0" encoding="utf-8"?> <!-- in drawable folder--> <ripple     xmlns:android="http://schemas.android.com/apk/res/android"     android:color="?android:colorcontrolhighlight">      <item android:id="@android:id/mask">         <shape android:shape="rectangle">             <solid android:color="?android:coloraccent" />         </shape>     </item>      <item>         <shape android:shape="rectangle">             <!-- put background color here-->             <solid android:color="@color/default_color" />         </shape>     </item>  </ripple> 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -