Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create RippleDrawable button in android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 222
    Comment on it

     In the below example I have created Ripple Drawable clickable button. Here first I have created RelativeLayout In Relative layout I have added a Button, after then I have created two xml layout in drawable folder first is one.xml layout in that I have added ripple attribute and second one is two.xml. In MainActivity I have used setBackgroundResource function. You can see below program it will clearly describe you " how to create RippleDrawable button in android".


    Step(1)activity_main.xml-
     

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.tutorialsbuzz.androidripple.MainActivity">
    
        <Button
            android:id="@+id/button_01"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/one"
        android:text="Click Me"/>
    
    </RelativeLayout>
    
    

    Step(2)-Created one.xml layout in drawable folder-
     

    <?xml version="1.0" encoding="utf-8"?>
    <ripple
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="@android:color/holo_blue_light">
    
        <item
            android:id="@android:id/mask"
            android:drawable="@color/colorwhite" />
    </ripple>
    
    

    Step(3)-Created two.xml layout in drawable folder
     

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item android:state_pressed="true">
            <shape>
                <solid android:color="@android:color/holo_blue_light"></solid>
            </shape>
        </item>
    
        <item >
            <shape>
                <solid android:color="@android:color/white"></solid>
            </shape>
        </item>
    
    </selector>

    Step(4)-MainActivity-
     

    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            final Button button_01 = (Button) findViewById(R.id.button_01);
            button_01.setBackgroundResource(R.drawable.one);
            button_01.setBackgroundResource(R.drawable.two);
    
        }
    }
    
    

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: