This is my code:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="title" >
<Preference
android:layout="@layout/custom_preference_layout"
android:title="@string/settings_rateUsOnGooglePlay" />
</PreferenceCategory>
</PreferenceScreen>
It is not possible to simply specify a margin/padding in the PreferenceScreen element. How do i add Margin/Padding to the preference screen?
Nov. 2019 Update: There is a solution, contrary to the first answer from years ago.
Option 1:
If you are inflating your PreferenceScreen
as a fragment into a FrameLayout
, you can assign a dp value to layout_marginTop
or layout_marginBottom
like so.
<FrameLayout
android:id="@+id/fragment_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="64dp" />
Option 2:
Otherwise, you can access the RecyclerView
object, (this contains the PreferenceScreen's items) in the fragment's OnViewCreated
like this:
// PreferenceFragment class
@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
final RecyclerView rv = getListView(); // This holds the PreferenceScreen's items
rv.setPadding(0, 0, 0, 56); // (left, top, right, bottom)
}
No, you cannot simply specify a padding/margin. It seems you need to either specify a custom layout or android:icon="@null"
like in
Android: How to adjust Margin/Padding in Preference?
Or you can try setting margin/padding programmatically like in
Android: How to maximize PreferenceFragment width (or get rid of margin)?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With