[英]An Image share to Multiple activities
Hi all, I would like to add an image to the right top corner that shares same data such as talking time, OnClickListener to all the activities like WeChat. 大家好,我想在右上角添加一个图像,以共享相同的数据,例如通话时间,OnClickListener等所有活动,例如微信。
I have an xml as following: 我有一个XML,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/calling"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="25dp"
android:background="@color/colorActive">
<ImageView
android:id="@+id/phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:padding="2dp"
android:scaleX="0.8"
android:scaleY="0.8"
android:src="@mipmap/ic_launcher_round" />
<TextView
android:id="@+id/timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/phone"
android:layout_centerHorizontal="true"
android:paddingBottom="2dp"
android:paddingLeft="2dp"
android:text="00:00"
android:textColor="@android:color/white" />
</RelativeLayout>
</LinearLayout>
But i don't know how to achieve this feature. 但我不知道如何实现此功能。 I tried to use base activity and this xml to all activities that i want.
我尝试将基本活动和此xml用于我想要的所有活动。 It looks not quite make sense.
看起来不太合理。 FAB?
FAB? or even more complicated.
甚至更复杂。 I have searched a lot online and there is no similar example like this.
我在网上搜索了很多内容,没有类似的例子。
Thank you for your help. 谢谢您的帮助。
Place the xml you posted in a separete layout file (say call_button.xml) 将您发布的xml放在单独的布局文件中(例如call_button.xml)
Now create an activity with name BaseActivity
and make all your other activities extend it. 现在,创建一个名称为
BaseActivity
的活动,并使所有其他活动对其进行扩展。
In the xml of your all other activities, add the following code: 在所有其他活动的xml中,添加以下代码:
<include
android:id="@+id/callButton"
layout="@layout/call_button" />
Now in your BaseActivity
handle the click. 现在,在您的
BaseActivity
处理单击。
findViewById(R.id.callButton).setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
//do your task.
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.