首页 > 解决方案 > 显示来自另一个活动的按钮

问题描述

我有两个活动/两个 XML。

我在( )中制作了一个 Facebook 按钮,我想在 ( ) 中显示 Facebooksignactivty.java按钮。sign.xmlhomeactivity.javahome.xml

如何使用在另一个活动中创建的按钮?

请给我一个例子。

标签: javaandroidandroid-layoutandroid-studio

解决方案


像这样创建 facebook_button.xml

<Button xmlns:android="http://schemas.android.com/apk/res/android"
id="@+id/fb_button"
android:layout_width="64dp"
android:layout_height="64dp" />

创建 sign.xml 布局文件并使用

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <include layout="@layout/facebook_button"></include>
    ....
</LinearLayout>

所以,在你的家庭活动中......

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <include layout="@layout/facebook_button"></include>
    ....
</LinearLayout>

推荐阅读