Skip to content

Commit

Permalink
fixed main bar icons
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaK2905 committed Feb 16, 2025
1 parent 0905eee commit b1b33c1
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 72 deletions.
45 changes: 34 additions & 11 deletions app/src/main/java/org/hackillinois/android/view/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,26 @@ class MainActivity : AppCompatActivity() {

private fun setupBottomAppBar() {
// by default, home button is selected
val selectedIconColor = ContextCompat.getColor(this, R.color.selectedAppBarIcon)
val unselectedIconColor = ContextCompat.getColor(this, R.color.unselectedAppBarIcon)
val selectedIconColor = ContextCompat.getColor(this, R.color.black)
val unselectedIconColor = ContextCompat.getColor(this, R.color.black)

// Set default icons (assume these are your unselected drawables)
bottomAppBar.homeButton.setImageResource(R.drawable.battle_png)
bottomAppBar.scheduleButton.setImageResource(R.drawable.schedule_png)
bottomAppBar.shopButton.setImageResource(R.drawable.shop_png)
bottomAppBar.profileButton.setImageResource(R.drawable.profile_png)

// Set default color filter on home button (as it's selected by default)
bottomAppBar.homeButton.setColorFilter(selectedIconColor)

val bottomBarButtons = listOf(
bottomAppBar.homeButton,
bottomAppBar.scheduleButton,
bottomAppBar.shopButton,
bottomAppBar.profileButton,
bottomAppBar.profileButton
)

// make all buttons unselectedColor and then set selected button to selectedColor
// Set click listeners for each button.
bottomBarButtons.forEach { button ->
button.setOnClickListener { view ->
val newSelection = bottomBarButtons.indexOf(button)
Expand All @@ -77,15 +84,31 @@ class MainActivity : AppCompatActivity() {
if (newSelection != currentSelection) {
currentSelection = newSelection

// change icon colors
// Reset all buttons: set unselected drawable and color filter.
bottomAppBar.homeButton.setImageResource(R.drawable.battle_png)
bottomAppBar.scheduleButton.setImageResource(R.drawable.schedule_png)
bottomAppBar.shopButton.setImageResource(R.drawable.shop_png)
bottomAppBar.profileButton.setImageResource(R.drawable.profile_png)
bottomBarButtons.forEach { (it as ImageButton).setColorFilter(unselectedIconColor) }
(view as ImageButton).setColorFilter(selectedIconColor)

// Set the clicked button to selected drawable and color filter.
when (view) {
bottomAppBar.homeButton -> switchFragment(HomeFragment(), false)
bottomAppBar.scheduleButton -> switchFragment(ScheduleFragment(), false)
bottomAppBar.shopButton -> switchFragment(ShopFragment(), false)
bottomAppBar.profileButton -> switchFragment(ProfileFragment(), false)
bottomAppBar.homeButton -> {
bottomAppBar.homeButton.setImageResource(R.drawable.battle_underlined_png)
switchFragment(HomeFragment(), false)
}
bottomAppBar.scheduleButton -> {
bottomAppBar.scheduleButton.setImageResource(R.drawable.schedule_underlined_png)
switchFragment(ScheduleFragment(), false)
}
bottomAppBar.shopButton -> {
bottomAppBar.shopButton.setImageResource(R.drawable.shop_underlined_png)
switchFragment(ShopFragment(), false)
}
bottomAppBar.profileButton -> {
bottomAppBar.profileButton.setImageResource(R.drawable.profile_underlined_png)
switchFragment(ProfileFragment(), false)
}
else -> return@setOnClickListener
}
}
Expand Down Expand Up @@ -113,7 +136,7 @@ class MainActivity : AppCompatActivity() {
bottomAppBar.shopButton,
bottomAppBar.profileButton,
)
val unselectedIconColor = ContextCompat.getColor(this, R.color.unselectedAppBarIcon)
val unselectedIconColor = ContextCompat.getColor(this, R.color.black)
bottomBarButtons.forEach { (it as ImageButton).setColorFilter(unselectedIconColor) }

// if not already on scanner selection page, switch fragment to scanner selection page
Expand Down
Binary file added app/src/main/res/drawable/battle_png.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/camera_png.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/ic_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="@color/unselectedAppBarIcon">
android:tint="@color/black">
<path
android:fillColor="@android:color/white"
android:pathData="M12,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM12,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/ic_today.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="@color/unselectedAppBarIcon">
android:tint="@color/black">
<path
android:pathData="M19,3H18V2C18,1.45 17.55,1 17,1C16.45,1 16,1.45 16,2V3H8V2C8,1.45 7.55,1 7,1C6.45,1 6,1.45 6,2V3H5C3.89,3 3.01,3.9 3.01,5L3,19C3,20.1 3.89,21 5,21H19C20.1,21 21,20.1 21,19V5C21,3.9 20.1,3 19,3ZM18,19H6C5.45,19 5,18.55 5,18V8H19V18C19,18.55 18.55,19 18,19ZM8,10H11C11.55,10 12,10.45 12,11V14C12,14.55 11.55,15 11,15H8C7.45,15 7,14.55 7,14V11C7,10.45 7.45,10 8,10Z"
android:fillColor="#FFFFFF"/>
Expand Down
Binary file added app/src/main/res/drawable/profile_png.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/schedule_png.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/shop_png.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/shop_underlined_png.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 11 additions & 57 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,8 @@
app:layout_constraintVertical_bias="0.0"
app:layout_constraintHorizontal_chainStyle="spread"
app:tint="@color/black"
app:srcCompat="@drawable/home_icon" />

<TextView
android:id="@+id/homeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="44dp"
android:gravity="center"
android:text="@string/home_icon"
android:textColor="@color/black"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="@id/homeButton"
app:layout_constraintTop_toTopOf="@id/homeButton" />
app:srcCompat="@drawable/battle_png" />


<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/scheduleButton"
Expand All @@ -63,19 +51,8 @@
app:layout_constraintEnd_toStartOf="@+id/placeholder"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/homeButton"
app:srcCompat="@drawable/calendar_icon" />

<TextView
android:id="@+id/calendarText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="44dp"
android:gravity="center"
android:text="@string/schedule_icon"
android:textColor="@color/black"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="@id/scheduleButton"
app:layout_constraintTop_toTopOf="@id/scheduleButton" />
app:srcCompat="@drawable/schedule_png" />


<View
android:id="@+id/placeholder"
Expand All @@ -98,20 +75,8 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/shopButton"
app:srcCompat="@drawable/profile_icon" />

<TextView
android:id="@+id/profileText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="44dp"
android:layout_marginStart="8dp"
android:gravity="center"
android:text="@string/profile_icon"
android:textColor="@color/black"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="@id/profileButton"
app:layout_constraintTop_toTopOf="@id/profileButton" />
app:srcCompat="@drawable/profile_png" />


<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/shopButton"
Expand All @@ -124,20 +89,8 @@
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/placeholder"
app:layout_constraintTop_toTopOf="@+id/homeButton"
app:srcCompat="@drawable/prizes_icon" />

<TextView
android:id="@+id/prizesText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="44dp"
android:layout_marginStart="8dp"
android:gravity="center"
android:text="@string/prizes_icon"
android:textColor="@color/black"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="@id/shopButton"
app:layout_constraintTop_toTopOf="@id/shopButton" />
app:srcCompat="@drawable/shop_png" />

</androidx.constraintlayout.widget.ConstraintLayout>

</com.google.android.material.bottomappbar.BottomAppBar>
Expand All @@ -149,9 +102,10 @@
app:backgroundTint="@color/cream"
android:layout_gravity="bottom|center"
android:layout_marginBottom="30dp"
android:layout_marginTop="20dp"
app:fabCustomSize="72dp"
app:maxImageSize="50dp"
app:srcCompat="@drawable/camera_icon" />
app:maxImageSize="40dp"
app:srcCompat="@drawable/camera_png" />



Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<color name="starColor">#ED9B21</color>
<color name="primaryTextColor">#08151B</color>
<color name="proTagColor">#6D9CA0</color>
<color name="selectedAppBarIcon">#ACCEBE</color> <!-- For bottom tab icons -->
<color name="unselectedAppBarIcon">#FFFFFF</color> <!-- For bottom tab icons -->
<!-- <color name="selectedAppBarIcon">#000000</color> &lt;!&ndash; For bottom tab icons &ndash;&gt;-->
<!-- <color name="unselectedAppBarIcon">#000000F</color> &lt;!&ndash; For bottom tab icons &ndash;&gt;-->

<!-- 2023 color palette (from leaderboard) -->
<color name="nightBlue">#0D387C</color>
Expand Down

0 comments on commit b1b33c1

Please sign in to comment.