AndroidStudio更换xml默认的布局

栏目: 编程工具 · Android · 发布时间: 6年前

内容简介:本文是自从 AndroidStudio 到 2.3 了以后,新建一个 Activity,默认的布局就从以前的

版权声明

本文是 开源实验室 原创文章,转载请以 链接 形式注明地址: https://kymjs.com/note/2018/09/09/01

对本知识点有任何问题,可加我的个人微信:kymjs123

自从 AndroidStudio 到 2.3 了以后,新建一个 Activity,默认的布局就从以前的 LinearLayout 变成了 Google 强推的 ConstraintLayout ,但其实这个布局是可以被修改的。

在 Mac 上改默认布局(Windows可以自己找对应的目录),需要编辑这个文件:

/Applications/Android\ Studio.app/Contents/plugins/android/lib/templates/activities/common/root/res/layout/simple.xml.ftl

同时附赠一个 AndroidStudio 中使用 Kotlin 默认的依赖是依赖了 kotlin-jre ,而这个 jre 早就被改 jetbrain 废弃了,修改 jre 为 jdk 可以编辑这个文件。

Applications/Android\ Studio.app/Contents/plugins/android/lib/templates/activities/common/kotlin_macros.ftl

下面是我自己使用的两个文件的内容,你可以直接复制走:

// simple.xml.ftl 文件的

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button"/>

</LinearLayout>

// kotlin_macros.ftl 文件的

<#-- Macro used to add the necessary dependencies to support kotlin to
an app build.gradle -->

<#macro addKotlinPlugins>
<#if generateKotlin>
<#compress>
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
</#compress>
</#if>
</#macro>

<#macro addKotlinDependencies>
<#if generateKotlin>${getConfigurationName("compile")} "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"</#if>
</#macro>

// TODO: <apply plugin /> Is adding the dependencies at the *end* of build.gradle
// TODO: The two macros above, addKotlinPlugins and addKotlinDependencies, are duplicating the work of addAllKotlinDependencies, when
//       creating a new project (isNewProject == true). The only reason is the above bug on <apply plugin />
<#macro addAllKotlinDependencies>
  <#if (language!'Java')?string == 'Kotlin'>
    <#if !isNewProject>
      <apply plugin="kotlin-android" />
      <apply plugin="kotlin-android-extensions" />
    </#if>
    <#if !hasDependency('org.jetbrains.kotlin:kotlin-stdlib')>
        <dependency mavenUrl="org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"/>
        <merge from="root://activities/common/kotlin.gradle.ftl"
                 to="${escapeXmlAttribute(projectLocation)}/build.gradle" />
    </#if>
  </#if>
</#macro>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

奇点临近

奇点临近

Ray Kurzweil / 董振华、李庆成 / 机械工业出版社 / 2011-10 / 69.00元

人工智能作为21世纪科技发展的最新成就,深刻揭示了科技发展为人类社会带来的巨大影响。本书结合求解智能问题的数据结构以及实现的算法,把人工智能的应用程序应用于实际环境中,并从社会和哲学、心理学以及神经生理学角度对人工智能进行了独特的讨论。本书提供了一个崭新的视角,展示了以人工智能为代表的科技现象作为一种“奇点”思潮,揭示了其在世界范围内所产生的广泛影响。本书全书分为以下几大部分:第一部分人工智能,第......一起来看看 《奇点临近》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具