Шаблон проекта
Some checks failed
Merge core/template-android-project to this repo / merge-if-needed (push) Failing after 15s
Some checks failed
Merge core/template-android-project to this repo / merge-if-needed (push) Failing after 15s
This commit is contained in:
parent
3e6fe310e0
commit
527e348293
53
README.md
Normal file
53
README.md
Normal file
@ -0,0 +1,53 @@
|
||||
[![Android Studio version](https://img.shields.io/endpoint?url=https%3A%2F%2Fsicampus.ru%2Fgitea%2Fcore%2Fdocs%2Fraw%2Fbranch%2Fmain%2Fandroid-studio-label.json)](https://sicampus.ru/gitea/core/docs/src/branch/main/how-upload-project.md)
|
||||
|
||||
# Практическая работа. Курс Kotlin. Практическая 3.10
|
||||
Данная практическая работа направлена на реализацию бокового меню приложения
|
||||
|
||||
## Дополнение XML разметки
|
||||
Первым делом необходимо дополнить разметку XML для корректного использования бокового меню. Необходимые места для заполнения представлены ниже.
|
||||
|
||||
Укажите параметры `app:headerLayout` и `app:menu` внутри NavigationView! Нужные XML уже реализованы внутри проекта
|
||||
*activity_main.xml*
|
||||
```xml
|
||||
...
|
||||
<com.google.android.material.navigation.NavigationView
|
||||
android:id="@+id/nav_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="start"
|
||||
android:fitsSystemWindows="true"
|
||||
<!-- TODO: Реализовать здесь -->
|
||||
/>
|
||||
```
|
||||
|
||||
Реализовать 3 item'а внутри `group` для реализации имен и значков меню. Идентификаторы, имена и наименования иконок должны соответствовать таблице ниже
|
||||
|id|title|icon|
|
||||
|--|-----|----|
|
||||
|home|Home|baseline_home_24|
|
||||
|about|About|baseline_back_hand_24|
|
||||
|help|Help|baseline_help_24|
|
||||
|
||||
*menu.xml*
|
||||
```xml
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<group android:checkableBehavior="single">
|
||||
<!-- TODO: Создайте 3 item'а -->
|
||||
</group>
|
||||
</menu>
|
||||
```
|
||||
|
||||
## Дополнение Kotlin кода
|
||||
Далее необходимо дополнить код для замены текста в TextView `info` на название элемента меню, а также вывод Toast по шаблону **Page: ИМЯ_ЭЛЕМЕНТА_МЕНЮ**
|
||||
|
||||
MainActivity.kt
|
||||
```kotlin
|
||||
...
|
||||
navigationView?.setNavigationItemSelectedListener(
|
||||
NavigationView.OnNavigationItemSelectedListener { item ->
|
||||
// TODO: Реализовать здесь
|
||||
drawerLayout?.closeDrawer(navigationView!!)
|
||||
false
|
||||
}
|
||||
)
|
||||
```
|
@ -10,7 +10,14 @@
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.Default"
|
||||
tools:targetApi="31" />
|
||||
android:theme="@style/Theme.Design.Light.NoActionBar"
|
||||
tools:targetApi="31">
|
||||
<activity android:name=".MainActivity" android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
41
app/src/main/java/ru/myitschool/work/MainActivity.kt
Normal file
41
app/src/main/java/ru/myitschool/work/MainActivity.kt
Normal file
@ -0,0 +1,41 @@
|
||||
package ru.myitschool.work
|
||||
|
||||
import android.os.Bundle
|
||||
import android.widget.EditText
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.drawerlayout.widget.DrawerLayout
|
||||
import com.google.android.material.navigation.NavigationView
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
var drawerLayout: DrawerLayout? = null
|
||||
var navigationView: NavigationView? = null
|
||||
var actionBarDrawerToggle: ActionBarDrawerToggle? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
setContentView(R.layout.activity_main)
|
||||
|
||||
drawerLayout = findViewById(R.id.drawer_layout)
|
||||
navigationView = findViewById(R.id.nav_view)
|
||||
actionBarDrawerToggle =
|
||||
ActionBarDrawerToggle(this, drawerLayout, R.string.open, R.string.close)
|
||||
|
||||
drawerLayout?.addDrawerListener(actionBarDrawerToggle!!)
|
||||
actionBarDrawerToggle!!.syncState()
|
||||
navigationView?.setNavigationItemSelectedListener(
|
||||
NavigationView.OnNavigationItemSelectedListener { item ->
|
||||
// TODO: Создать тост по шаблону "Page: *имя элемента из меню*"
|
||||
// TODO: Заменить текст в текстовом поле info
|
||||
drawerLayout?.closeDrawer(navigationView!!)
|
||||
false
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
5
app/src/main/res/drawable/baseline_back_hand_24.xml
Normal file
5
app/src/main/res/drawable/baseline_back_hand_24.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
|
||||
|
||||
<path android:fillColor="@android:color/white" android:pathData="M13,24c-3.26,0 -6.19,-1.99 -7.4,-5.02l-3.03,-7.61C2.26,10.58 3,9.79 3.81,10.05l0.79,0.26c0.56,0.18 1.02,0.61 1.24,1.16L7.25,15H8V3.25C8,2.56 8.56,2 9.25,2s1.25,0.56 1.25,1.25V12h1V1.25C11.5,0.56 12.06,0 12.75,0S14,0.56 14,1.25V12h1V2.75c0,-0.69 0.56,-1.25 1.25,-1.25c0.69,0 1.25,0.56 1.25,1.25V12h1V5.75c0,-0.69 0.56,-1.25 1.25,-1.25S21,5.06 21,5.75V16C21,20.42 17.42,24 13,24z"/>
|
||||
|
||||
</vector>
|
5
app/src/main/res/drawable/baseline_help_24.xml
Normal file
5
app/src/main/res/drawable/baseline_help_24.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
|
||||
|
||||
<path android:fillColor="@android:color/white" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,19h-2v-2h2v2zM15.07,11.25l-0.9,0.92C13.45,12.9 13,13.5 13,15h-2v-0.5c0,-1.1 0.45,-2.1 1.17,-2.83l1.24,-1.26c0.37,-0.36 0.59,-0.86 0.59,-1.41 0,-1.1 -0.9,-2 -2,-2s-2,0.9 -2,2L8,9c0,-2.21 1.79,-4 4,-4s4,1.79 4,4c0,0.88 -0.36,1.68 -0.93,2.25z"/>
|
||||
|
||||
</vector>
|
5
app/src/main/res/drawable/baseline_home_24.xml
Normal file
5
app/src/main/res/drawable/baseline_home_24.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
|
||||
|
||||
<path android:fillColor="@android:color/white" android:pathData="M10,20v-6h4v6h5v-8h3L12,3 2,12h3v8z"/>
|
||||
|
||||
</vector>
|
41
app/src/main/res/layout/activity_main.xml
Normal file
41
app/src/main/res/layout/activity_main.xml
Normal file
@ -0,0 +1,41 @@
|
||||
<?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:fitsSystemWindows="true"
|
||||
android:id="@+id/drawer_layout">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/info"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="163dp"
|
||||
android:layout_marginTop="60dp"
|
||||
android:layout_marginEnd="164dp"
|
||||
android:layout_marginBottom="356dp"
|
||||
android:text="This is center"
|
||||
android:textSize="20sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<com.google.android.material.navigation.NavigationView
|
||||
android:id="@+id/nav_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="start"
|
||||
android:fitsSystemWindows="true" />
|
||||
<!-- TODO: Укажите параметры app:headerLayout и app:menu внутри NavigationView! -->
|
||||
|
||||
|
||||
</androidx.drawerlayout.widget.DrawerLayout>
|
16
app/src/main/res/layout/header.xml
Normal file
16
app/src/main/res/layout/header.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?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="200dp"
|
||||
android:padding="25dp"
|
||||
android:background="@color/cardview_dark_background"
|
||||
android:gravity="bottom">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Header"
|
||||
android:textSize="24sp"
|
||||
android:textColor="@color/white"/>
|
||||
|
||||
</LinearLayout>
|
9
app/src/main/res/menu/menu.xml
Normal file
9
app/src/main/res/menu/menu.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<group android:checkableBehavior="single">
|
||||
<!-- TODO: Создайте 3 item'а -->
|
||||
<!-- TODO: id=home icon=baseline_home_24 -->
|
||||
<!-- TODO: id=about icon=baseline_back_hand_24 -->
|
||||
<!-- TODO: id=help icon=baseline_help_24 -->
|
||||
</group>
|
||||
</menu>
|
@ -1,3 +1,5 @@
|
||||
<resources>
|
||||
<string name="app_name">Work</string>
|
||||
<string name="open">Open</string>
|
||||
<string name="close">Close</string>
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user