Compare commits
1 Commits
Fragment
...
bottomNavi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ad6e171a14 |
@@ -1,13 +1,21 @@
|
||||
package com.a1.nextlocation;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.a1.nextlocation.R;
|
||||
import com.a1.nextlocation.fragments.HomeFragment;
|
||||
import com.a1.nextlocation.fragments.RouteFragment;
|
||||
import com.a1.nextlocation.fragments.SettingsFragment;
|
||||
import com.a1.nextlocation.fragments.StatisticFragment;
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
/**
|
||||
* onCreate method that creates the main activity
|
||||
* @param savedInstanceState the saved instance state of the app
|
||||
@@ -16,5 +24,33 @@ public class MainActivity extends AppCompatActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
BottomNavigationView bottomNav = findViewById(R.id.navbar);
|
||||
bottomNav.setOnNavigationItemSelectedListener(navListener);
|
||||
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, new HomeFragment()).commit();
|
||||
}
|
||||
|
||||
|
||||
private BottomNavigationView.OnNavigationItemSelectedListener navListener = item -> {
|
||||
Fragment selectedFragment = null;
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.locations:
|
||||
selectedFragment = new HomeFragment();
|
||||
break;
|
||||
case R.id.routes:
|
||||
selectedFragment = new RouteFragment();
|
||||
break;
|
||||
case R.id.statistics:
|
||||
selectedFragment = new StatisticFragment();
|
||||
break;
|
||||
case R.id.settings:
|
||||
selectedFragment = new SettingsFragment();
|
||||
break;
|
||||
}
|
||||
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, selectedFragment).commit();
|
||||
return true;
|
||||
};
|
||||
}
|
||||
10
app/src/main/res/drawable/ic_home.xml
Normal file
10
app/src/main/res/drawable/ic_home.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M10,20v-6h4v6h5v-8h3L12,3 2,12h3v8z"/>
|
||||
</vector>
|
||||
10
app/src/main/res/drawable/ic_placeholder.xml
Normal file
10
app/src/main/res/drawable/ic_placeholder.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:pathData="M17.6,11.48 L19.44,8.3a0.63,0.63 0,0 0,-1.09 -0.63l-1.88,3.24a11.43,11.43 0,0 0,-8.94 0L5.65,7.67a0.63,0.63 0,0 0,-1.09 0.63L6.4,11.48A10.81,10.81 0,0 0,1 20L23,20A10.81,10.81 0,0 0,17.6 11.48ZM7,17.25A1.25,1.25 0,1 1,8.25 16,1.25 1.25,0 0,1 7,17.25ZM17,17.25A1.25,1.25 0,1 1,18.25 16,1.25 1.25,0 0,1 17,17.25Z"
|
||||
android:fillColor="@android:color/white"/>
|
||||
</vector>
|
||||
@@ -16,7 +16,7 @@
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
/>
|
||||
|
||||
<view
|
||||
<View
|
||||
android:id="@+id/scroller_devider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
@@ -40,4 +40,6 @@
|
||||
app:menu="@menu/navmenu"
|
||||
/>
|
||||
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -4,21 +4,25 @@
|
||||
<item
|
||||
android:id="@+id/locations"
|
||||
android:title="@string/locations"
|
||||
android:icon="@drawable/ic_placeholder"
|
||||
/>
|
||||
|
||||
<item
|
||||
android:id="@+id/routes"
|
||||
android:title="@string/routes"
|
||||
android:icon="@drawable/ic_placeholder"
|
||||
/>
|
||||
|
||||
<item
|
||||
android:id="@+id/statistics"
|
||||
android:title="@string/statistics"
|
||||
android:icon="@drawable/ic_placeholder"
|
||||
/>
|
||||
|
||||
<item
|
||||
android:id="@+id/settings"
|
||||
android:title="@string/settings"
|
||||
android:icon="@drawable/ic_placeholder"
|
||||
/>
|
||||
|
||||
</menu>
|
||||
Reference in New Issue
Block a user