Custom Slider Drawer Android Studio
<?xml version="1.0" encoding="utf-8"?><!--<?xml version="1.0" encoding="utf-8"?>-->
<androidx.drawerlayout.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AppMainScreen"
tools:openDrawer="left">
<!-- Main Content -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
<!-- Drawer Design Starts Here -->
<androidx.core.widget.NestedScrollView
android:layout_width="@dimen/_230sdp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:elevation="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Drawer Header -->
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/white"
android:outlineAmbientShadowColor="#000000"
app:cardCornerRadius="0dp"
app:cardElevation="@dimen/_15sdp"
app:strokeWidth="0dp">
</com.google.android.material.card.MaterialCardView>
<!-- Drawer Items -->
<!-- Add more drawer items here -->
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.drawerlayout.widget.DrawerLayout>
Activity Java Code
// Find the DrawerLayout
DrawerLayout drawerLayout = findViewById(R.id.drawer_layout);
// Find the Button and set an OnClickListener to open the drawer
ImageView iv_drawerOpen = findViewById(R.id.iv_drawerOpen);
ImageView iv_drawerClose = findViewById(R.id.iv_drawerClose);
iv_drawerOpen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
drawerLayout.openDrawer(GravityCompat.START,true);
}
});
iv_drawerClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
drawerLayout.closeDrawer(GravityCompat.START,true);
}
});
Comments
Post a Comment