跳至主要内容

android Button add ripple effects


Method 1:  To Add Ripple Effect/Animation to a Android Button

Just replace your button background attribute with android:background="?attr/selectableItemBackground" and your code looks like this.
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:text="Click Me" />


Method 2:  To Add Ripple Effect/Animation to a Android Button

Using this method, you can customize ripple effect color. First, you have to create a xml file in your drawable resource directory. Create a ripple_effect.xml file and add following code.
res/drawable/ripple_effect.xml
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="#f816a463"
tools:targetApi="lollipop">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#f816a463" />
</shape>
</item>
</ripple>
view rawripple_effect.xml hosted with ❤ by GitHub


And set background of button to above drawable resource file. Final code of xml layout activity looks like this.
res/layout/ button_ripple_effect.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Click the below buttons to see ripple effect" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ripple_effect"
android:padding="16dp"
android:text="Click Me" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/ripple_effect"
android:padding="16dp"
android:text="Click Me" />
</LinearLayout>

评论

  1. Are you sick & tired from looking for bitcoin faucets?
    Triple your claiming speed with this advanced BTC FAUCET ROTATOR.

    回复删除
  2. Invest in Ripple on eToro the World’s Leading Social Trading Network!

    Join 1,000,000's who have already discovered smarter strategies for investing in Ripple.

    Learn from profitable eToro traders or copy their trades automatically.

    回复删除
  3. YoBit lets you to claim FREE CRYPTO-COINS from over 100 unique crypto-currencies, you complete a captcha once and claim as much as coins you need from the available offers.

    After you make about 20-30 claims, you complete the captcha and proceed to claiming.

    You can click on CLAIM as much as 30 times per one captcha.

    The coins will stored in your account, and you can convert them to Bitcoins or any other currency you want.

    回复删除

发表评论

此博客中的热门博文

android hide actionbar

public class MainActivity extends Activity { ActionBar actionBar; //声明ActionBar @Override protected void onCreate( Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView( R .layout.activity_main); actionBar = getSupportActionBar(); //得 到ActionBar actionBar.hide(); //隐藏ActionBar } }

go url encoding

func  QueryUnescape func QueryUnescape (s string ) ( string , error ) QueryUnescape does the inverse transformation of QueryEscape, converting %AB into the byte 0xAB and '+' into ' ' (space). It returns an error if any % is not followed by two hexadecimal digits. func  QueryUnescape func QueryUnescape (s string ) ( string , error ) QueryUnescape does the inverse transformation of QueryEscape, converting %AB into the byte 0xAB and '+' into ' ' (space). It returns an error if any % is not followed by two hexadecimal digits.