1) Past this code in build.gradle file
compile 'com.chauthai.swipereveallayout:swipe-reveal-layout:1.4.0'
2) MainActivity.xml File Coding
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context="comide.codechef.httpswww.swipemenu.MainActivity"
>
<!-- SwipeRevealLayout -->
<com.chauthai.swipereveallayout.SwipeRevealLayout
android:id="@+id/swipe_layout_1"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_margin="10dp">
<!-- Menu Item In LinearLayout-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="70dp"
android:layout_height="match_parent"
android:gravity="center"
android:background="@android:color/darker_gray"
android:textColor="@android:color/white"
android:text="Yes"
android:onClick="moreOnClick"/>
<TextView
android:layout_width="70dp"
android:layout_height="match_parent"
android:gravity="center"
android:background="@android:color/holo_red_dark"
android:textColor="@android:color/white"
android:text="No"
android:onClick="deleteOnClick"/>
<TextView
android:layout_width="70dp"
android:layout_height="match_parent"
android:gravity="center"
android:background="@android:color/darker_gray"
android:textColor="@android:color/white"
android:text="Later"
android:onClick="deleteOnClick"/>
</LinearLayout>
<!-- FrameLayout For Want to Swipe-->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/border_solid_white"
android:onClick="layoutOneOnClick">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My Layout 1"
android:textColor="#000000"
android:textStyle="bold"
android:gravity="center"
android:layout_gravity="center"/>
</FrameLayout>
</com.chauthai.swipereveallayout.SwipeRevealLayout>
</LinearLayout>
3) Set Event In Java Codding
package comide.codechef.httpswww.swipemenu;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void layoutOneOnClick(View v) {
Toast.makeText(MainActivity.this, "Layout 1 clicked", Toast.LENGTH_SHORT).show();
}
public void layoutTwoOnClick(View v) {
Toast.makeText(MainActivity.this, "Layout 2 clicked", Toast.LENGTH_SHORT).show();
}
public void layoutThreeOnClick(View v) {
Toast.makeText(MainActivity.this, "Layout 3 clicked", Toast.LENGTH_SHORT).show();
}
public void layoutFourOnClick(View v) {
Toast.makeText(MainActivity.this, "Layout 4 clicked", Toast.LENGTH_SHORT).show();
}
public void moreOnClick(View v) {
Toast.makeText(MainActivity.this, "More clicked", Toast.LENGTH_SHORT).show();
}
public void laterOnClick(View v) {
Toast.makeText(MainActivity.this, "Later clicked", Toast.LENGTH_SHORT).show();
}
public void deleteOnClick(View v) {
Toast.makeText(MainActivity.this, "Delete clicked", Toast.LENGTH_SHORT).show();
}
}
Watch Output In Below Video Link
No comments:
Post a Comment