PreferenceFragmentCompat has iconSpaceReserved true by default












0














I've migrated to androidx.* libraries and one of them is the new preferences library:
androidx.preference:preference:1.1.0-alpha01 - the latest version of it.



As said in release notes iconSpaceReserved attribute not working correctly with PreferenceCategories is fixed.



But looks like it's set to true by default.



I've built demo project to test it.



PreferencesFragment



import androidx.preference.PreferenceFragmentCompat;

public class SetttingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.preferences);
}
}


preferences.xml



<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory android:title="Category 1">
<Preference
android:key="pref1"
android:title="Preference 1" />
<Preference
android:key="pref2"
android:title="Preference 2" />
</PreferenceCategory>
<PreferenceCategory
android:title="Category 2"
app:iconSpaceReserved="false">
<Preference
android:key="pref3"
android:title="Preference 3" />
<Preference
android:key="pref4"
android:title="Preference 4"
app:iconSpaceReserved="false" />
</PreferenceCategory>
...
</PreferenceScreen>


Preferences theme is set as needed.



styles.xml



<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>


Screenshot



PreferencesFragment



When app:iconSpaceReserved=false is set manually (as you can see on PreferenceCategory 2 and Preference 4) it works fine, but otherwise a space for icon is reserved.
Also docs says that it's false by default:




By default, preference icon view visibility will be set to GONE when there is no icon provided, so the default value of this attribute is false.




Is it a new bug in this library or a new feature to leave space for icon if it's not set? Or am I doing something wrong?



I know about workarounds:




  • PreferenceFragmentCompat has padding on PreferenceCategory that I can't get rid of

  • How to get remove margin/padding in Preference Screen




Edit:



After looking through the sources I found the next thing.



PreferenceThemeOverlay -> anyPreferenceStyle has set the attribute



<item name="iconSpaceReserved">@bool/config_materialPreferenceIconSpaceReserved</item>


which refers to



values/values.xml
<bool name="config_materialPreferenceIconSpaceReserved">false</bool>


and



values-sw360dp-v13/values-sw360dp-v13.xml
<bool name="config_materialPreferenceIconSpaceReserved">true</bool>


For some reason it's set to true here.










share|improve this question
























  • I've not used that yet, but looking through the source, it seems PreferenceThemeOverlay.v14.Material is deprecated – android.googlesource.com/platform/frameworks/support/+/…. Try using PreferenceThemeOverlay instead. All of the styles in that theme have iconSpaceReserved set to false (actually, they're set to a bool resource value that's false).
    – Mike M.
    Nov 23 '18 at 9:03












  • @MikeM. thanks, forgot to check this. But nothing changed, padding is still there.
    – Sabre
    Nov 23 '18 at 9:11










  • Well, I'm having machine issues, atm, and can't pull that to test. Have you tried to check the theme value of iconSpaceReserved at runtime, just to see if the resource value is wrong, or if it's an issue in the Preference classes?
    – Mike M.
    Nov 23 '18 at 9:54










  • @MikeM. Thanks for the suggestion, done. When iconSpaceReserved is not set manually it returns true (for example, Preference 1 on my screenshot), if set to false manually returns false (Preference 4) as expected. Tested it on my physical device with API 26 and on emulators with different APIs (including 28). Also Layout Inspector shows some padding.
    – Sabre
    Nov 23 '18 at 10:12








  • 1




    Ah, it is true, though, in values-sw360dp, so same diff.
    – Mike M.
    Nov 23 '18 at 10:29
















0














I've migrated to androidx.* libraries and one of them is the new preferences library:
androidx.preference:preference:1.1.0-alpha01 - the latest version of it.



As said in release notes iconSpaceReserved attribute not working correctly with PreferenceCategories is fixed.



But looks like it's set to true by default.



I've built demo project to test it.



PreferencesFragment



import androidx.preference.PreferenceFragmentCompat;

public class SetttingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.preferences);
}
}


preferences.xml



<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory android:title="Category 1">
<Preference
android:key="pref1"
android:title="Preference 1" />
<Preference
android:key="pref2"
android:title="Preference 2" />
</PreferenceCategory>
<PreferenceCategory
android:title="Category 2"
app:iconSpaceReserved="false">
<Preference
android:key="pref3"
android:title="Preference 3" />
<Preference
android:key="pref4"
android:title="Preference 4"
app:iconSpaceReserved="false" />
</PreferenceCategory>
...
</PreferenceScreen>


Preferences theme is set as needed.



styles.xml



<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>


Screenshot



PreferencesFragment



When app:iconSpaceReserved=false is set manually (as you can see on PreferenceCategory 2 and Preference 4) it works fine, but otherwise a space for icon is reserved.
Also docs says that it's false by default:




By default, preference icon view visibility will be set to GONE when there is no icon provided, so the default value of this attribute is false.




Is it a new bug in this library or a new feature to leave space for icon if it's not set? Or am I doing something wrong?



I know about workarounds:




  • PreferenceFragmentCompat has padding on PreferenceCategory that I can't get rid of

  • How to get remove margin/padding in Preference Screen




Edit:



After looking through the sources I found the next thing.



PreferenceThemeOverlay -> anyPreferenceStyle has set the attribute



<item name="iconSpaceReserved">@bool/config_materialPreferenceIconSpaceReserved</item>


which refers to



values/values.xml
<bool name="config_materialPreferenceIconSpaceReserved">false</bool>


and



values-sw360dp-v13/values-sw360dp-v13.xml
<bool name="config_materialPreferenceIconSpaceReserved">true</bool>


For some reason it's set to true here.










share|improve this question
























  • I've not used that yet, but looking through the source, it seems PreferenceThemeOverlay.v14.Material is deprecated – android.googlesource.com/platform/frameworks/support/+/…. Try using PreferenceThemeOverlay instead. All of the styles in that theme have iconSpaceReserved set to false (actually, they're set to a bool resource value that's false).
    – Mike M.
    Nov 23 '18 at 9:03












  • @MikeM. thanks, forgot to check this. But nothing changed, padding is still there.
    – Sabre
    Nov 23 '18 at 9:11










  • Well, I'm having machine issues, atm, and can't pull that to test. Have you tried to check the theme value of iconSpaceReserved at runtime, just to see if the resource value is wrong, or if it's an issue in the Preference classes?
    – Mike M.
    Nov 23 '18 at 9:54










  • @MikeM. Thanks for the suggestion, done. When iconSpaceReserved is not set manually it returns true (for example, Preference 1 on my screenshot), if set to false manually returns false (Preference 4) as expected. Tested it on my physical device with API 26 and on emulators with different APIs (including 28). Also Layout Inspector shows some padding.
    – Sabre
    Nov 23 '18 at 10:12








  • 1




    Ah, it is true, though, in values-sw360dp, so same diff.
    – Mike M.
    Nov 23 '18 at 10:29














0












0








0







I've migrated to androidx.* libraries and one of them is the new preferences library:
androidx.preference:preference:1.1.0-alpha01 - the latest version of it.



As said in release notes iconSpaceReserved attribute not working correctly with PreferenceCategories is fixed.



But looks like it's set to true by default.



I've built demo project to test it.



PreferencesFragment



import androidx.preference.PreferenceFragmentCompat;

public class SetttingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.preferences);
}
}


preferences.xml



<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory android:title="Category 1">
<Preference
android:key="pref1"
android:title="Preference 1" />
<Preference
android:key="pref2"
android:title="Preference 2" />
</PreferenceCategory>
<PreferenceCategory
android:title="Category 2"
app:iconSpaceReserved="false">
<Preference
android:key="pref3"
android:title="Preference 3" />
<Preference
android:key="pref4"
android:title="Preference 4"
app:iconSpaceReserved="false" />
</PreferenceCategory>
...
</PreferenceScreen>


Preferences theme is set as needed.



styles.xml



<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>


Screenshot



PreferencesFragment



When app:iconSpaceReserved=false is set manually (as you can see on PreferenceCategory 2 and Preference 4) it works fine, but otherwise a space for icon is reserved.
Also docs says that it's false by default:




By default, preference icon view visibility will be set to GONE when there is no icon provided, so the default value of this attribute is false.




Is it a new bug in this library or a new feature to leave space for icon if it's not set? Or am I doing something wrong?



I know about workarounds:




  • PreferenceFragmentCompat has padding on PreferenceCategory that I can't get rid of

  • How to get remove margin/padding in Preference Screen




Edit:



After looking through the sources I found the next thing.



PreferenceThemeOverlay -> anyPreferenceStyle has set the attribute



<item name="iconSpaceReserved">@bool/config_materialPreferenceIconSpaceReserved</item>


which refers to



values/values.xml
<bool name="config_materialPreferenceIconSpaceReserved">false</bool>


and



values-sw360dp-v13/values-sw360dp-v13.xml
<bool name="config_materialPreferenceIconSpaceReserved">true</bool>


For some reason it's set to true here.










share|improve this question















I've migrated to androidx.* libraries and one of them is the new preferences library:
androidx.preference:preference:1.1.0-alpha01 - the latest version of it.



As said in release notes iconSpaceReserved attribute not working correctly with PreferenceCategories is fixed.



But looks like it's set to true by default.



I've built demo project to test it.



PreferencesFragment



import androidx.preference.PreferenceFragmentCompat;

public class SetttingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.preferences);
}
}


preferences.xml



<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory android:title="Category 1">
<Preference
android:key="pref1"
android:title="Preference 1" />
<Preference
android:key="pref2"
android:title="Preference 2" />
</PreferenceCategory>
<PreferenceCategory
android:title="Category 2"
app:iconSpaceReserved="false">
<Preference
android:key="pref3"
android:title="Preference 3" />
<Preference
android:key="pref4"
android:title="Preference 4"
app:iconSpaceReserved="false" />
</PreferenceCategory>
...
</PreferenceScreen>


Preferences theme is set as needed.



styles.xml



<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>


Screenshot



PreferencesFragment



When app:iconSpaceReserved=false is set manually (as you can see on PreferenceCategory 2 and Preference 4) it works fine, but otherwise a space for icon is reserved.
Also docs says that it's false by default:




By default, preference icon view visibility will be set to GONE when there is no icon provided, so the default value of this attribute is false.




Is it a new bug in this library or a new feature to leave space for icon if it's not set? Or am I doing something wrong?



I know about workarounds:




  • PreferenceFragmentCompat has padding on PreferenceCategory that I can't get rid of

  • How to get remove margin/padding in Preference Screen




Edit:



After looking through the sources I found the next thing.



PreferenceThemeOverlay -> anyPreferenceStyle has set the attribute



<item name="iconSpaceReserved">@bool/config_materialPreferenceIconSpaceReserved</item>


which refers to



values/values.xml
<bool name="config_materialPreferenceIconSpaceReserved">false</bool>


and



values-sw360dp-v13/values-sw360dp-v13.xml
<bool name="config_materialPreferenceIconSpaceReserved">true</bool>


For some reason it's set to true here.







android android-preferences androidx preferencefragment






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 9:57







Sabre

















asked Nov 23 '18 at 8:53









SabreSabre

2,16452647




2,16452647












  • I've not used that yet, but looking through the source, it seems PreferenceThemeOverlay.v14.Material is deprecated – android.googlesource.com/platform/frameworks/support/+/…. Try using PreferenceThemeOverlay instead. All of the styles in that theme have iconSpaceReserved set to false (actually, they're set to a bool resource value that's false).
    – Mike M.
    Nov 23 '18 at 9:03












  • @MikeM. thanks, forgot to check this. But nothing changed, padding is still there.
    – Sabre
    Nov 23 '18 at 9:11










  • Well, I'm having machine issues, atm, and can't pull that to test. Have you tried to check the theme value of iconSpaceReserved at runtime, just to see if the resource value is wrong, or if it's an issue in the Preference classes?
    – Mike M.
    Nov 23 '18 at 9:54










  • @MikeM. Thanks for the suggestion, done. When iconSpaceReserved is not set manually it returns true (for example, Preference 1 on my screenshot), if set to false manually returns false (Preference 4) as expected. Tested it on my physical device with API 26 and on emulators with different APIs (including 28). Also Layout Inspector shows some padding.
    – Sabre
    Nov 23 '18 at 10:12








  • 1




    Ah, it is true, though, in values-sw360dp, so same diff.
    – Mike M.
    Nov 23 '18 at 10:29


















  • I've not used that yet, but looking through the source, it seems PreferenceThemeOverlay.v14.Material is deprecated – android.googlesource.com/platform/frameworks/support/+/…. Try using PreferenceThemeOverlay instead. All of the styles in that theme have iconSpaceReserved set to false (actually, they're set to a bool resource value that's false).
    – Mike M.
    Nov 23 '18 at 9:03












  • @MikeM. thanks, forgot to check this. But nothing changed, padding is still there.
    – Sabre
    Nov 23 '18 at 9:11










  • Well, I'm having machine issues, atm, and can't pull that to test. Have you tried to check the theme value of iconSpaceReserved at runtime, just to see if the resource value is wrong, or if it's an issue in the Preference classes?
    – Mike M.
    Nov 23 '18 at 9:54










  • @MikeM. Thanks for the suggestion, done. When iconSpaceReserved is not set manually it returns true (for example, Preference 1 on my screenshot), if set to false manually returns false (Preference 4) as expected. Tested it on my physical device with API 26 and on emulators with different APIs (including 28). Also Layout Inspector shows some padding.
    – Sabre
    Nov 23 '18 at 10:12








  • 1




    Ah, it is true, though, in values-sw360dp, so same diff.
    – Mike M.
    Nov 23 '18 at 10:29
















I've not used that yet, but looking through the source, it seems PreferenceThemeOverlay.v14.Material is deprecated – android.googlesource.com/platform/frameworks/support/+/…. Try using PreferenceThemeOverlay instead. All of the styles in that theme have iconSpaceReserved set to false (actually, they're set to a bool resource value that's false).
– Mike M.
Nov 23 '18 at 9:03






I've not used that yet, but looking through the source, it seems PreferenceThemeOverlay.v14.Material is deprecated – android.googlesource.com/platform/frameworks/support/+/…. Try using PreferenceThemeOverlay instead. All of the styles in that theme have iconSpaceReserved set to false (actually, they're set to a bool resource value that's false).
– Mike M.
Nov 23 '18 at 9:03














@MikeM. thanks, forgot to check this. But nothing changed, padding is still there.
– Sabre
Nov 23 '18 at 9:11




@MikeM. thanks, forgot to check this. But nothing changed, padding is still there.
– Sabre
Nov 23 '18 at 9:11












Well, I'm having machine issues, atm, and can't pull that to test. Have you tried to check the theme value of iconSpaceReserved at runtime, just to see if the resource value is wrong, or if it's an issue in the Preference classes?
– Mike M.
Nov 23 '18 at 9:54




Well, I'm having machine issues, atm, and can't pull that to test. Have you tried to check the theme value of iconSpaceReserved at runtime, just to see if the resource value is wrong, or if it's an issue in the Preference classes?
– Mike M.
Nov 23 '18 at 9:54












@MikeM. Thanks for the suggestion, done. When iconSpaceReserved is not set manually it returns true (for example, Preference 1 on my screenshot), if set to false manually returns false (Preference 4) as expected. Tested it on my physical device with API 26 and on emulators with different APIs (including 28). Also Layout Inspector shows some padding.
– Sabre
Nov 23 '18 at 10:12






@MikeM. Thanks for the suggestion, done. When iconSpaceReserved is not set manually it returns true (for example, Preference 1 on my screenshot), if set to false manually returns false (Preference 4) as expected. Tested it on my physical device with API 26 and on emulators with different APIs (including 28). Also Layout Inspector shows some padding.
– Sabre
Nov 23 '18 at 10:12






1




1




Ah, it is true, though, in values-sw360dp, so same diff.
– Mike M.
Nov 23 '18 at 10:29




Ah, it is true, though, in values-sw360dp, so same diff.
– Mike M.
Nov 23 '18 at 10:29












1 Answer
1






active

oldest

votes


















0














I've posted this on the Issue Tracker and got the following answer:




This is intended and part of the Material spec for Settings. See
Material Design guide under 'Alignment'.







share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53443354%2fpreferencefragmentcompat-has-iconspacereserved-true-by-default%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I've posted this on the Issue Tracker and got the following answer:




    This is intended and part of the Material spec for Settings. See
    Material Design guide under 'Alignment'.







    share|improve this answer


























      0














      I've posted this on the Issue Tracker and got the following answer:




      This is intended and part of the Material spec for Settings. See
      Material Design guide under 'Alignment'.







      share|improve this answer
























        0












        0








        0






        I've posted this on the Issue Tracker and got the following answer:




        This is intended and part of the Material spec for Settings. See
        Material Design guide under 'Alignment'.







        share|improve this answer












        I've posted this on the Issue Tracker and got the following answer:




        This is intended and part of the Material spec for Settings. See
        Material Design guide under 'Alignment'.








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 13:52









        SabreSabre

        2,16452647




        2,16452647






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53443354%2fpreferencefragmentcompat-has-iconspacereserved-true-by-default%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Berounka

            Sphinx de Gizeh

            Different font size/position of beamer's navigation symbols template's content depending on regular/plain...