how to hide the divider between preferences in fragment

牧云@^-^@ 提交于 2019-12-05 00:47:08

if you are using PreferenceFragmentCompat , it is using Recycle view so you have to use this code . This automatically hides the divider

@Nullable
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {

   setDivider(new ColorDrawable(Color.TRANSPARENT));
   setDividerHeight(0);
}

These solutions didn't work for me. Here's what I did in PreferenceFragmentCompat:

@Override
public void setDivider(Drawable divider) {
    super.setDivider(new ColorDrawable(Color.TRANSPARENT));
}

@Override
public void setDividerHeight(int height) {
    super.setDividerHeight(0);
}

You can remove your divider by style.

<style name="PreferenceFragment.Material">
    <item name="android:divider">@null</item>
</style>

Define custom preference theme without dividers in your style.xml:

<style name="PrefsTheme" parent="PreferenceThemeOverlay.v14.Material">
    <item name="android:divider">@null</item>
    <item name="android:dividerHeight">0dp</item>
</style>

and don't forget to use it in your main app theme which is also in style.xml:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- ... -->
    <item name="preferenceTheme">@style/PrefsTheme</item>
</style>
prakash

First: if used the listview in xml

set the android:dividerHeight="0dp" in listview in xml file ,

second:

ListView list = (ListView) findViewById(android.R.id.list);
list.setDivider(new ColorDrawable(Color.TRANSPARENT)); // or some other color int
list.setDividerHeight((int) getResources().getDisplayMetrics().density); 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!