Search code examples
androidandroid-relativelayoutandroid-constraintlayout

How to change the default behaviour of Android Studio


Can we change the default Build behavior of Android Studio from Constraint to Relative Layout?

Problem: Sometimes it takes more time to Clean/Rebuild my project. And I never use Constraint Layout, so I want to set the build behavior of Android Studio from Constraint Layout to Relative Layout.

I want every-time I open AS, it should open Relative. Is it possible to achieve?


Solution

  • Quite Easy - just in 3 steps

    1. Goto C:\Program Files\Android\Android Studio\plugins\android\lib\templates\activities\common\root\res\layout
    2. Backup simple.xml.ftl
    3. Modify simple.xml.ftl to below code and save it

    <RelativeLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="${packageName}.${activityClass}">
    
    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:text="Sample"
        android:textSize="16sp" />
    </RelativeLayout>
    

    Tried and tested on Windows 10 build:gradle:3.0.1

    • Works for every new activity in the same project and for future projects as well.
    • Note: Need to modify the simple.xml.ftl file with Admin rights
    • For this to work out you don't need to edit layout > New > Edit File Templates... your layoutResourceFile and layoutResourceFile_vertical by removing the ${ROOT_TAG} - as I have already tried but that doesn't work.