java - 显示来自另一个活动的按钮
问题描述
我有两个活动/两个 XML。
我在( )中制作了一个 Facebook 按钮,我想在 ( ) 中显示 Facebooksignactivty.java
按钮。sign.xml
homeactivity.java
home.xml
如何使用在另一个活动中创建的按钮?
请给我一个例子。
解决方案
像这样创建 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>
推荐阅读
- linux - Unix 用户级别如何影响我对 docker 映像的可见性?
- android - 计算到特定时区午夜的秒数
- javascript - 在 try/catch 块中成功异步请求后执行语句
- c++ - 交错插入排序功能无法正确排序
- android - Expo with Android Studio Emulator 错误:“Error running adb: This computer is not authorized to debug the device”
- php - 文件夹中的 HTML 图像不再出现 (PHP)
- python - 如果日期是周末 - 自动重新运行该功能
- c++ - 什么方法可以创建一个 16 字节的校验和
- oracle - 将数学公式转换为 Oracle 函数
- php - 请帮助解析json