Android 工具:指向多个活动的上下文链接
我已经读过,并发现它在开发过程中非常有用,因为它帮助我了解我使用了当前Xml的哪些活动 我的问题是: 我有两个活动,使用相同的Xml文件(重用相同的Android 工具:指向多个活动的上下文链接,android,android-layout,android-xml,android-tools-namespace,Android,Android Layout,Android Xml,Android Tools Namespace,我已经读过,并发现它在开发过程中非常有用,因为它帮助我了解我使用了当前Xml的哪些活动 我的问题是: 我有两个活动,使用相同的Xml文件(重用相同的layout.Xml文件),但我无法使用工具:context 如何使用Xml中的tools:context链接2个活动 我试过: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/r
layout.Xml
文件),但我无法使用工具:context
如何使用Xml中的tools:context
链接2个活动
我试过:
<?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="wrap_content"
tools:context="com.example.mytestapp.MainActivity,com.example.mytestapp.Main2Activity">
<!-- Other Layouts Here -->
</RelativeLayout>
你到底希望发生什么?添加的唯一好处是预览编辑器,它实际上不需要关于活动的任何细节,除了用于该活动的主题。当我在xml文件中进行更改时,我需要知道其中连接的所有活动,因此,我可以轻松地进行更改删除工具:上下文行我认为您应该改为使用项目范围内的搜索来搜索
R.layout.file
,这将为您提供引用该文件的所有Java文件。或者只添加一个XML注释。context属性并不是一个列表或引用源,据我所知,Android Studio 3.0.1足够智能,可以使用带有根元素定义的类图标向您显示文件使用的所有链接,因此您不需要添加工具上下文
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:tools2="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.example.mytestapp.MainActivity"
tools2:context="com.example.mytestapp.Main2Activity">
<!-- Other Layouts Here -->
</RelativeLayout>
Error:(2) error: duplicate attribute.
Error:(2) duplicate attribute.