Closed andreluizreis closed 6 years ago
There are two problems with your XML:
androidx.preference.PreferenceCategory
) because the lib overrides some of the preferences by defining the same class and prefixing it with the appropriate package name. The solution is simple: just remove androidx.preference.
everywhere. app:allowDividerBelow="false"
to the first category.@Gericop Now that I removed the androidx.preference.
from the XML. I am receiving the old error back: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getPaddingStart()' on a null object reference
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getPaddingStart()' on a null object reference
at androidx.core.view.ViewCompat.getPaddingStart(ViewCompat.java:1527)
at com.takisoft.preferencex.PreferenceCategory.onBindViewHolder(PreferenceCategory.java:146)
at androidx.preference.PreferenceGroupAdapter.onBindViewHolder(PreferenceGroupAdapter.java:381)
at androidx.preference.PreferenceGroupAdapter.onBindViewHolder(PreferenceGroupAdapter.java:45)
at androidx.recyclerview.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6781)
at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6823)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5752)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6019)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854)
at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230)
at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1557)
at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517)
at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612)
at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3924)
at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3641)
at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4194)
at android.view.View.layout(View.java:16784)
at android.view.ViewGroup.layout(ViewGroup.java:5333)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
at android.view.View.layout(View.java:16784)
at android.view.ViewGroup.layout(ViewGroup.java:5333)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1702)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1556)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1465)
at android.view.View.layout(View.java:16784)
at android.view.ViewGroup.layout(ViewGroup.java:5333)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
at android.view.View.layout(View.java:16784)
at android.view.ViewGroup.layout(ViewGroup.java:5333)
at androidx.appcompat.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:444)
at android.view.View.layout(View.java:16784)
at android.view.ViewGroup.layout(ViewGroup.java:5333)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
at android.view.View.layout(View.java:16784)
at android.view.ViewGroup.layout(ViewGroup.java:5333)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1702)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1556)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1465)
at android.view.View.layout(View.java:16784)
at android.view.ViewGroup.layout(ViewGroup.java:5333)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
at android.view.View.layout(View.java:16784)
at android.view.ViewGroup.layout(ViewGroup.java:5333)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2370)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2079)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1230)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6731)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777)
at android.view.Choreographer.doCallbacks(Choreographe
Okay, I see the problem. In your custom layout, you set for the PreferenceCategory
, there's no parent of the TextView
(id=@android:id/title
). For the time being, make sure there's a parent view for the TextView
(or just stop using the custom layout, it looks weird to me).
@Gericop, the left padding was solved when I added app:iconSpaceReserved="false"
in the Switches. The link that you sent me helped me a lot (https://stackoverflow.com/questions/51518758/preferencefragmentcompat-has-padding-on-preferencecategory-that-i-cant-get-rid). However, it only works for API 21 and above.
When I test with API 16, the paddings still have problems and your fix now doesn't make difference. If I remove the library, the issue continues the same.
I don't understand why the divider moved to the PreferenceCategory and not between the items as it was before.
I saw that the new material design guideline shows the divider between groups and not items. So, if I follow the new guideline, my problem is this extra header title that I have in my app. I need to find a way to remove the divider from them. Because I am adding an extra PreferenceCategory
between some groups.
@andreluizreis Like is said before, the divider can be removed: use a hidden API (see #111) to tell the lib not to render the line below the first element by adding the attribute app:allowDividerBelow="false"
to the first category.
Also, I did not send you that link. The solution is to not use fully qualified names (e.g. androidx.preference.PreferenceCategory
) but the class name alone (e.g. PreferenceCategory
) and specify app:iconSpaceReserved="false"
for the category as well. Note that you might need to update your custom category layout so that the title TextView
will be inside a parent view.
@Gericop I did all the modifications that you advised me. It's working most of the screens now. However, the only downside is that to use SwitchPreferenceCompat
, I need to keep androidx.preference.PreferenceScreen
. If I remove androidx.preference
, I will receive an error element is not allowed here
. Right now, only API 16 with small screens the padding is wrong. I will try to fix that change the dimensions of padding dynamically.
@andreluizreis That is just a lint error, you can ignore it.
@Gericop, Thanks for helping me solve this problem these days. I will keep my design like the image below. I removed the header titles and I split into two different fragments. Now, I don't have more problems with the dividers.
We can close this issue now. I really appreciate the attention that you gave me. I wish you the best.
@andreluizreis You can also use nested PreferenceScreen
s to show the fine-grained settings on separate pages. Check out the sample app for details.
My settings page looked like that before.
Now it's looking like that.
This is API 16 Old phone
Manifest
I am using this Theme:
I am importing these libraries:
pref_notification.xml
I'm extending from
PreferenceFragmentCompat
calling this method as mentioned.