工具:多个活动的上下文链接

时间:2017-12-07 05:41:32

标签: android android-layout android-xml android-tools-namespace

我已经阅读了tools:context并发现它在开发时非常有用,因为它帮助我了解我使用当前Xml的哪些活动。

我的问题是:

我有两个活动,使用相同的Xml文件(重复使用相同的layout.xml文件),但我无法使用tools: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 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.

0 个答案:

没有答案