Bottom Navigation Activity
Bottom Navigation Activity è un tipo di progetto vuoto in cui è presente una barra menù nella parte bassa dello schermo.
AndroidManifest.xml
bottom_nav_menu.xml
activity_main.xml
MainActivity.kt
Bottom Navigation Activity è un tipo di progetto vuoto in cui è presente una barra menù nella parte bassa dello schermo.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.dm.tutorialbottomnavigationactivity"> | |
<application | |
android:allowBackup="true" | |
android:icon="@mipmap/ic_launcher" | |
android:label="@string/app_name" | |
android:roundIcon="@mipmap/ic_launcher_round" | |
android:supportsRtl="true" | |
android:theme="@style/AppTheme"> | |
<activity | |
android:name=".MainActivity" | |
android:label="@string/app_name"> | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN"/> | |
<category android:name="android.intent.category.LAUNCHER"/> | |
</intent-filter> | |
</activity> | |
</application> | |
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.constraint.ConstraintLayout | |
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/container" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".MainActivity"> | |
<TextView | |
android:id="@+id/message" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginLeft="@dimen/activity_horizontal_margin" | |
android:layout_marginTop="@dimen/activity_vertical_margin" | |
android:text="@string/title_home" | |
app:layout_constraintLeft_toLeftOf="parent" | |
app:layout_constraintTop_toTopOf="parent" | |
android:textSize="28sp"/> | |
<android.support.design.widget.BottomNavigationView | |
android:id="@+id/nav_view" | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:layout_marginEnd="0dp" | |
android:layout_marginStart="0dp" | |
android:background="?android:attr/windowBackground" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintLeft_toLeftOf="parent" | |
app:layout_constraintRight_toRightOf="parent" | |
app:menu="@menu/bottom_nav_menu"/> | |
</android.support.constraint.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dm.tutorialbottomnavigationactivity | |
import android.os.Bundle | |
import android.support.design.widget.BottomNavigationView | |
import android.support.v7.app.AppCompatActivity | |
import android.widget.TextView | |
class MainActivity : AppCompatActivity() { | |
private lateinit var textMessage: TextView | |
private val onNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item -> | |
when (item.itemId) { | |
R.id.navigation_home -> { | |
textMessage.setText(R.string.title_home) | |
return@OnNavigationItemSelectedListener true | |
} | |
R.id.navigation_dashboard -> { | |
textMessage.setText(R.string.title_dashboard) | |
return@OnNavigationItemSelectedListener true | |
} | |
R.id.navigation_notifications -> { | |
textMessage.setText(R.string.title_notifications) | |
return@OnNavigationItemSelectedListener true | |
} | |
} | |
false | |
} | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
val navView: BottomNavigationView = findViewById(R.id.nav_view) | |
textMessage = findViewById(R.id.message) | |
navView.setOnNavigationItemSelectedListener(onNavigationItemSelectedListener) | |
} | |
} |
Download Project | ![]() |
Download file APK | ![]() |
Visualizza su | ![]() |
Commenti
Posta un commento