如何在 xml 中自动导入 "xmlns:app="http....pk/res-auto"?或如何创建包含此 "xmlns:app" 方案的模板 xml?
How to import "xmlns:app="http....pk/res-auto" in xml automatically? or How to creat a template xml which includes this "xmlns:app" scheme?
众所周知,ConstraintLayout 现在是 android 开发中最流行和最高效的布局。但是要使用它的属性,您必须先导入“xmlns:app”。当您需要使用 ConstraintLayout 创建许多 xml 文件时,这非常烦人。如何使用此方案(“xmlns:app”)自动创建 xml 文件?我需要一个模板而不是手动导入它。
我认为最好的方法是在 Android Studio 中使用 Live Templates
。它允许您创建代码片段并在几秒钟内将它们添加到代码中:
这里是 XML 的例子:
https://riggaroo.dev/create-live-templates-android-studio/
所以你真正能做的就是把这个:
<androidx.constraintlayout.widget.ConstraintLayout 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">
</androidx.constraintlayout.widget.ConstraintLayout>
在 Android Studio -> 首选项 -> 实时模板
简单的方法是转到文件 -> 新建 -> 编辑文件模板.. -> 单击 + 按钮 -> 将您的 ConstraintLayout 布局粘贴到此处 -> 单击确定。完毕。
要使用它:右键单击 -> 新建 -> MyXML(您的 xml 文件名)
在这里。转到设置 -> 菜单和工具栏 -> 项目视图弹出菜单 -> 按 Alt + 向上(Alt + 向下)更改从模板的位置,单击确定应用它
众所周知,ConstraintLayout 现在是 android 开发中最流行和最高效的布局。但是要使用它的属性,您必须先导入“xmlns:app”。当您需要使用 ConstraintLayout 创建许多 xml 文件时,这非常烦人。如何使用此方案(“xmlns:app”)自动创建 xml 文件?我需要一个模板而不是手动导入它。
我认为最好的方法是在 Android Studio 中使用 Live Templates
。它允许您创建代码片段并在几秒钟内将它们添加到代码中:
这里是 XML 的例子:
https://riggaroo.dev/create-live-templates-android-studio/
所以你真正能做的就是把这个:
<androidx.constraintlayout.widget.ConstraintLayout 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">
</androidx.constraintlayout.widget.ConstraintLayout>
在 Android Studio -> 首选项 -> 实时模板
简单的方法是转到文件 -> 新建 -> 编辑文件模板.. -> 单击 + 按钮 -> 将您的 ConstraintLayout 布局粘贴到此处 -> 单击确定。完毕。
要使用它:右键单击 -> 新建 -> MyXML(您的 xml 文件名)
在这里。转到设置 -> 菜单和工具栏 -> 项目视图弹出菜单 -> 按 Alt + 向上(Alt + 向下)更改从模板的位置,单击确定应用它