question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[PreferenceFragmentCompat] Dialogs are not shown in Material Design M3 style

See original GitHub issue

Description: Dialogs in [PreferenceFragmentCompat] are not shown in Material Design M3 style. Instead, for example, wrong colors and dialog outlines are used as shown below. The issue is especially visible when using the DynamicColors feature. Screenshot_20220602_190913

Expected behavior: I expected that [PreferenceFragmentCompat] shows dialogs in Material Design M3 style, i.e. about as shown below (I’ve tried to rebuild the expected M3 design by using a ThemeOverlay, but didn’t manage e.g. to get the correct backgrounc color). Screenshot_20220602_191920

Source code: Here are some code snippets…

PreferenceFragmentCompat

public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {

    private Context mContext;

    @Override
    public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
        // Load the preferences from an XML resource
        setPreferencesFromResource(R.xml.settings, rootKey);
    }

themes.xml

<resources xmlns:tools="http://schemas.android.com/tools">

    <!-- Base application theme -->
    <style name="AppTheme" parent="AppTheme.Base" />
    <style name="AppTheme.Base" parent="Theme.Material3.Light">

Android API version: 32 & 33 (Tiramisu)

Material Library version: com.google.android.material:material:1.7.0-alpha02

Device: Pixel 5 Emulator

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
drchencommented, Jun 3, 2022

Oh gotcha. So with MaterialAlertDialogBuilder the surface color is calculated on-the-fly (for now) - a small percentage of ?attr/colorPrimary is overlaid upon the pure ?attr/colorSurface. We have no control over the framework alert dialog, so the color you see will be pure ?attr/colorSurface.

To achieve the same color, the easiest way might be setting the color programmatically after the dialog is created - by using SurfaceColors.SURFACE_3.getColor().

Another approach is overriding ?android:attr/windowBackground and manually overlaying the color with layer-list. Here’s an example to refer to: https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/menu/res/drawable-v23/m3_popupmenu_background_overlay.xml

0reactions
ytheekshanacommented, Oct 2, 2022

Could any one give me a full code on this. I also have a list-preference which I need to support m3

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adjust androidx.preference dialogs to follow Material You
Now, i themed my app to use and follow the new Material3 (or Material You) theme, but a problem i'm facing is that...
Read more >
Dialogs – Material Design 3
Dialogs provide important prompts in a user flow. ... Dialogs should appear in response to a user task or an action, with relevant...
Read more >
Releases · material-components/material-components-android
Modular and customizable Material Design UI components for Android - Releases ... is hidden (ed11e69); Updated tooltip shape style to use M3 shape...
Read more >
androidx.compose.material3 - Android Developers
The Material Design type scale includes a range of contrasting styles that ... the given style with the current style values for any...
Read more >
Everything you need to know about Material Design 3
UI Components got a style refresh too. Generally speaking, Material Design 3 adopts a simpler, more playful look. It features rounder elements, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found