2swan

Navigation Menu 커스텀 본문

Programming/Android Function

Navigation Menu 커스텀

2swan 2023. 8. 12. 17:25

main.xml

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:id="@+id/drawer_layout">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <Button
            android:id="@+id/btn_open"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="대문열기"/>

    </LinearLayout>
    <include layout="@layout/activity_drawer"/>


</androidx.drawerlayout.widget.DrawerLayout>

 

activity_drawer.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:layout_gravity="start"
    android:background="#BCB2CCE1"
    android:orientation="vertical"
    android:id="@+id/drawer">

    <Button
        android:id="@+id/btn_close"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:text="메뉴닫기"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="메뉴" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#E4DA81"
        android:orientation="vertical"
        android:layout_margin="10dp">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="테스트 메뉴"/>
    </LinearLayout>


</LinearLayout>

 

main.activity

public class MainActivity extends AppCompatActivity {

    private DrawerLayout drawerLayout;
    private  View drawerView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

       drawerLayout = findViewById(R.id.drawer_layout);
       drawerView = findViewById(R.id.drawer);

       Button btn_open = findViewById(R.id.btn_open);

       btn_open.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               drawerLayout.openDrawer(drawerView);
           }
       });

       Button btn_close =  findViewById(R.id.btn_close);
       btn_close.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               drawerLayout.closeDrawers();
           }
       });

       drawerLayout.setDrawerListener(listener);
       drawerView.setOnTouchListener(new View.OnTouchListener() {
           @Override
           public boolean onTouch(View view, MotionEvent motionEvent) {
               return true;
           }
       });

    }

    DrawerLayout.DrawerListener listener = new DrawerLayout.DrawerListener() {
        @Override
        public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {

        }

        @Override
        public void onDrawerOpened(@NonNull View drawerView) {

        }

        @Override
        public void onDrawerClosed(@NonNull View drawerView) {

        }

        @Override
        public void onDrawerStateChanged(int newState) {

        }
    };

}

결과 값

'Programming > Android Function' 카테고리의 다른 글

RegisterForActivityResult  (0) 2023.08.12
ListView  (0) 2023.08.12
ImageView & Toast  (0) 2023.08.12
Intent 화면전환  (0) 2023.08.12
SQlite 예제  (0) 2023.08.08