How to get padding/margin resources used in PreferenceActivity in Android?

680 Views Asked by At

I have a settings activity that extends PreferenceActivity. However, I also have a custom preference that I added using my own layout. The question is, how can I use the same resource (padding/margin) in my own layout? I want all the elements in the list look aligned.

1

There are 1 best solutions below

3
Mohammed Alloboany On BEST ANSWER

You can define a dimens file in res/values directory

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Default screen margins, per the Android Design guidelines. -->
    <dimen name="activity_horizontal_margin">16dp</dimen>
</resources>

Then use this variable in all place you want, it is easy if you want to modify the design of app, it costs just one edit.

<TextView
    android:id="@+id/skip"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:margin="@dimen/activity_horizontal_margin"
    android:text="@string/start_"
    android:textColor="@color/white"
    android:textSize="16sp"/>