Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BottomNavigationView] Font changing to bold when selected #3293

Closed
danWon12 opened this issue Mar 6, 2023 · 9 comments
Closed

[BottomNavigationView] Font changing to bold when selected #3293

danWon12 opened this issue Mar 6, 2023 · 9 comments

Comments

@danWon12
Copy link

danWon12 commented Mar 6, 2023

Description: Until the 1.8 Release the NavigationBarItemView was styleable with the attributes itemTextAppearanceActive and itemTextAppearanceInactive (or textAppearanceTitleSmall depending from which theme we are inheriting). Since the release there is a hardcoded line which makes the font bold when selected:
11e98f2

Expected behavior: The user of the library can still decide if the font should be bold when selected. Looking at the TODO one live above it seems like it should be styleable with Tokens. Unfortunately, the design documentation for Material3 does not force selected items to be bold and it does not mention how to style the font of an active/inactive item.
Does an item have to be in bold font when selected?
How can we change the font weight in this case without Material 3 or with Material3?

Source code: 11e98f2

Material Library version: Material Android Library version you are using here (1.8.0 and 1.9.0-alpha2)

@ardakazanci-mobven
Copy link

Did you find an workaround solution?

@Yakoot
Copy link

Yakoot commented Apr 18, 2023

same problem

@hollmannlu
Copy link

same within our projects. we cannot update beyond 1.7.0

@mrzbn
Copy link

mrzbn commented May 9, 2023

same problem here

@enginegl
Copy link

+1

@Radiokot
Copy link

Workaround if you can't avoid updating the library: extend the BottomNavigationView hierarchy to reset the active label typeface after it is made bold 🥴

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.widget.TextView
import com.google.android.material.bottomnavigation.BottomNavigationItemView
import com.google.android.material.bottomnavigation.BottomNavigationMenuView
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.navigation.NavigationBarItemView
import com.google.android.material.navigation.NavigationBarMenuView

class NoBoldBottomNavigationView @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null
) : BottomNavigationView(context, attrs) {
    @SuppressLint("RestrictedApi")
    override fun createNavigationBarMenuView(context: Context): NavigationBarMenuView {
        return object : BottomNavigationMenuView(context) {
            override fun createNavigationBarItemView(context: Context): NavigationBarItemView {
                return object : BottomNavigationItemView(context) {
                    override fun setTextAppearanceActive(activeTextAppearance: Int) {
                        val largeLabel: TextView? =
                            findViewById(com.google.android.material.R.id.navigation_bar_item_large_label_view)
                        val defaultLargeLabelTypeface = largeLabel?.typeface

                        super.setTextAppearanceActive(activeTextAppearance)

                        if (defaultLargeLabelTypeface != null) {
                            largeLabel.typeface = defaultLargeLabelTypeface
                        }
                    }
                }
            }
        }
    }
}

@paulfthomas
Copy link
Member

@Radiokot We're working on adding a new attr for controlling the boldness separately, it should be available soon, sorry for the inconvenience and thanks for the workaround.

@SeniorZhai
Copy link

You can try this. app:itemTextAppearanceActiveBoldEnabled

@danWon12
Copy link
Author

danWon12 commented Feb 7, 2024

This works. Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants