Comments (14)
Reported the issue to Google: https://code.google.com/p/android/issues/detail?id=213297
from android-support-preference-v7-fix.
Just about to report this issues. Thank you for reporting this. Is there any "hack" can be done, like what you had done on 23 support library?
from android-support-preference-v7-fix.
Okay, I found the bug (it is more of an Android View-handling thing though).
In PreferenceGroupAdapter
's onCreateViewHolder(...)
after inflating the layout, the paddings are good. Right after this, there's a setBackgroundDrawable(...)
call which resets them all to zero. It is a known behavior as per Romain Guy:
The reason why setting an image resets the padding is because 9-patch images can encode padding.
The solution would be the following:
- Save the paddings after inflating the layout.
- Set the background drawable.
- Set the saved paddings on the layout.
Since the Android devs decided to make a lot of things private in this class (including an inner static class), it'd be extremely difficult to fix it only by overriding a few things...
from android-support-preference-v7-fix.
Tried a lot of "nice" things (i.e. not rewriting layouts / classes), nothing worked and I don't really get the reason why.
Here's a piece from the v17 preference_category_material.xml
layout file:
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" />
And this solution should work (it's in v17 styles.xml; the test app uses PreferenceFixTheme.Light.NoActionBar
which inherits its attributes from PreferenceFixTheme.Light
):
<style name="PreferenceFixTheme.Light" parent="@style/Theme.AppCompat.Light">
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
<item name="colorAccent">@color/preference_accent</item>
<item name="dialogTheme">@style/PreferenceFixTheme.Light.Dialog</item>
<item name="alertDialogTheme">@style/PreferenceFixTheme.Light.Dialog.Alert</item>
<!-- Padding fix -->
<item name="android:listPreferredItemPaddingStart">16dp</item>
<item name="android:listPreferredItemPaddingEnd">16dp</item>
</style>
The funny thing is that in the preference_material.xml
file (notice the difference), there's also this attribute:
android:minHeight="?android:attr/listPreferredItemHeightSmall"
If I override it by defining its value in the same PreferenceFixTheme.Light
style, it works:
<item name="android:listPreferredItemHeightSmall">100dp</item>
So I guess the padding is really just preferred and gets overridden by either a direct piece of code or the measurements done during layout.
from android-support-preference-v7-fix.
Thanks, In your previous workaround, I already include
<!-- Padding fix -->
<item name="android:listPreferredItemPaddingStart">16dp</item>
<item name="android:listPreferredItemPaddingEnd">16dp</item>
in v17. It works fine all time till recently when we switch to support library 24.
I also observe same problem in device with v16. But, android:listPreferredItemPaddingStart
and android:listPreferredItemPaddingEnd
are not found in v16.
Hope Google can deliver a fix on this. Without library 24, we can't take advantage of Firebase.
from android-support-preference-v7-fix.
It was just an example, all the API levels below 21 are affected by it. API 7-14 uses android:listPreferredItemPaddingLeft
and android:listPreferredItemPaddingRight
, but the problem persists.
from android-support-preference-v7-fix.
I did some experiments with it on API 14 by copying the preference_material.xml
to the project and hard-coding the padding into it and still no success, so I'm guessing that it is being overridden in a class. Moreover, I set the height of the layout to the right padding's attribute and it worked which confirms my theory...
from android-support-preference-v7-fix.
Interesting, I've already had the PreferenceCategory
class because it still messes up the accent color without it, so I decided to get the padding of the title view in onBindViewHolder(...)
. It returns plain 0 for all of the padding values. It pretty much seems like the inflater just doesn't care about the paddings anymore and sets(?) them to 0. The category itself has a hard-coded 16dip paddingTop, which is also ignored, while the bottom margin (also set to 16 dip) is there normally. If I set the paddings from code, they take effect and show just how normally they would.
from android-support-preference-v7-fix.
I found a way to hack in the left and right paddings, but the top one is still messed up.
from android-support-preference-v7-fix.
Seems that with reflection I've been able to fix this ridiculous bug. I'll release the v24.0.0.0-beta version soon...
from android-support-preference-v7-fix.
The fix has been released. Use compile 'com.takisoft.fix:preference-v7:24.0.0.0-beta'
in your projects.
from android-support-preference-v7-fix.
Thanks for your work. Going to try it out tonight.
from android-support-preference-v7-fix.
Hi @Gericop
Thanks for the hard work.
However, I realize, it is not work perfectly with inner preference yet.
Here's the screnshot
Here's the XML for the preference screen - https://gist.github.com/yccheok/4172d782249757b1153cee9edd4c566b
Thanks.
from android-support-preference-v7-fix.
Sorry. The inner preference bug I mentioned is not valid anymore. Please ignore it.
from android-support-preference-v7-fix.
Related Issues (20)
- .setcancelable for Dialog? HOT 1
- how to show divider between preference when merged to androidX-1.0.0/support-28 HOT 1
- ColorPickerPreference dialog style HOT 1
- how to get items from custom view HOT 1
- [AndroidX] android:dependency doesn't change color of preference HOT 5
- PreferenceScreen deprecated in Android Q HOT 2
- Request to update the version of the preference library HOT 5
- Broken when using with latest AndroidX material alpha05 and appcompat alpha04 HOT 8
- keyboard do not hide when cancel button is clicked of editTextPreference HOT 2
- Issue with themes HOT 3
- NullPointerException in PreferenceFragmentCompat.traverseAndRefreshPrefs()
- Popup menu android doesn't work correctly HOT 1
- NumberFormatException in RingtonePreferenceDialogFragmentCompat HOT 7
- AndroidX 1.1.0 HOT 4
- Expand/Contract PreferenceCategory HOT 3
- Question about migrating from library fix:preference-v7:28.0.0.0 to preferencex:preferencex:1.1.0
- How do you get the value from ColorPickerPreference
- Exception: java.lang.NumberFormatException HOT 1
- How to add a ad in a Preference Screen? HOT 1
- ListPreference Crash on theme change (Light to Dark or Vice versa) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-support-preference-v7-fix.