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.
I have an xml as following:
<?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. It looks not quite make sense. 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)
Now create an activity with name BaseActivity
and make all your other activities extend it.
In the xml of your all other activities, add the following code:
<include
android:id="@+id/callButton"
layout="@layout/call_button" />
Now in your BaseActivity
handle the click.
findViewById(R.id.callButton).setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
//do your task.
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.