728x90
728x90
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/drawer_layout"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<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>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/colorAccent"
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:text="๋์ ๋ฉ๋ด"
android:textSize="30dp"
android:gravity="center"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="10dp"
android:background="#D84646">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ํ
์คํธ ๋ฉ๋ด1"
android:gravity="center"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ํ
์คํธ ๋ฉ๋ด2"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
package com.example.customnaviexample;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.drawerlayout.widget.DrawerLayout.DrawerListener;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
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 = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerView = (View) 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);
}
});
// ์ด ๋ฌธ์ฅ ์
๋ ฅ ์ ์ค๋ฅ๊ฐ ๋์ง ์๊ธฐ ์ํด ์๋ ๋ฆฌ์ค๋๋ฅผ ์์ฑํด์ผํจํจ
drawerLayout.setDrawerListener(listener);
//
drawerView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
return true;
}
});
// ๋๋ก์ฐ ๋ฉ๋ด์์ ์ด ๋ฒํผ ํด๋ฆญ ์ ์ก์
( ๋ซ๋ ์ก์
)
Button btn_close = (Button)findViewById(R.id.btn_close);
btn_close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
drawerLayout.closeDrawers();
}
});
}
// ํน์ ์ก์
์ ๋ํด ์ถ๊ฐ ๊ธฐ๋ฅ์ ๊ตฌํํ ์ ์์
DrawerLayout.DrawerListener listener = new 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) {
}
};
}
728x90
๋ฐ์ํ
'๐ Programming > Android' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
App ๋ฒ์ ๊ด๋ฆฌ์ ํ์์ฑ - ์๋งจํฑ ๋ฒ์ ๊ด๋ฆฌ (Sementic Versioning) (0) | 2023.09.07 |
---|---|
#9 WebView(์น ๋ทฐ) - err_cleartext_not_permitted ํด๊ฒฐ๋ฒ (0) | 2020.05.05 |
#8 SharedPreference(์์ด๋ ํ๋ฆฌํผ๋ฐ์ค) (0) | 2020.05.05 |