Poperton
Poperton

Reputation: 2127

How to change font type, font size and bold text in Android style (PopUpMenu)

How do I change things like font size, font type and bold text in a PopUpMenu?

<style name="AppTheme.PopupMenu" parent="ThemeOverlay.AppCompat.Dark">
    <item name="android:textColor">@color/colorPrimary</item>
    <item name="android:textColorSecondary">@color/colorSecondary</item>
    <item name="android:popupBackground">@color/black</item>
</style>

I'm doing like this to add this style:

Context wrapper = new ContextThemeWrapper(MainActivity.this, R.style.AddEffectsStyle);
PopupMenu popup = new PopupMenu(wrapper, binding.btnAddEffect);

I tried adding, for example:

    <item name="android:textStyle">bold</item>

but text won't turn bold.

How do I change thee things I mentioned?

Upvotes: 1

Views: 338

Answers (1)

Priyank-py
Priyank-py

Reputation: 369

Try doing this:

<style name="YOURSTYLE" parent="Widget.AppCompat.PopupMenu">
    <item name="android:textColor">@android:color/white</item>
    <item name="android:textStyle">bold</item>
    <item name="android:textSize">24sp</item>
    <item name="android:fontFamily">sans-serif-condensed</item>
    <item name="android:itemBackground">@android:color/holo_red_light</item>
</style>

And for your java:

Context wrapper = new ContextThemeWrapper(MainActivity.this, R.style.YOURSTYLE);
PopupMenu popup = new PopupMenu(wrapper, view);
popup.inflate(R.menu.main_menu);
popup.show();

Works perfectly for me.

Here's how it looks

Upvotes: 2

Related Questions