Android – set padding / margins as the top activity / fragment layout container in the theme?

In my application, I want to fill all screen top-level containers that apply to themes

For example:

This is the layout file

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <EditText
        android:id="@+id/edt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</RelativeLayout>

This is the application theme

<!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowFrame">@drawable/window_frame</item>
    </style>

I can use Android: padding to apply padding to the parent container relativelayout. But I don't want to, because I need to specify the same content in each layout file. I want to define it in the theme apptheme

Any solution would be appreciated

resolvent:

Why do you need to write additional code that uses styles?

You can set padding directly in RES / values / dimensions.xml, which is much easier. Whenever you need to increase or decrease values, you only need to change it in a single location for each activity

For example, in dimensions.xml

<dimen name="my_activity_padding">5dp</dimen> 

Then in the active layout:

android:padding="@dimen/activity_padding"

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>