If you had an action_bar.xml
layout like this:
<?xml version="1.0" encoding="utf-8"?>
<com.your.package.ui.widget.ActionBar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/actionBar"
android:layout_width="fill_parent"
android:layout_height="58dip"
android:background="@drawable/action_bar_background" >
<ImageButton
android:id="@+id/actionBarOpenButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:contentDescription="open button"
android:src="@drawable/action_bar_open_button" />
</com.your.package.ui.widget.ActionBar>
You would then have a class in the package com.your.package.ui.widget
Called ActionBar.java
that looked like this:
package com.your.package.ui.widget;
public class ActionBar extends LinearLayout implements OnClickListener {
public ActionBar(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ActionBar(Context context) {
super(context);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
findViewById(R.id.actionBarOpenButton).setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.actionBarOpenButton:
// Do something
break;
default:
break;
}
}
}
You would then include it in another layout say `activity_main.xml' like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<include layout="@layout/action_bar" />
<!-- Rest of your layout -->
</LinearLayout>
You can then include it in any Actvitity you want and your custom widget will do the same onClick event everywhere.