**OnCreate() :-**
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK) {
Intent returnIntent = new Intent();
setResult(RESULT_CANCELED, returnIntent);
this.finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
ActionBar mActionBar = getActionBar();
mActionBar.setDisplayShowHomeEnabled(false);
mActionBar.setDisplayShowTitleEnabled(false);
LayoutInflater mInflater = LayoutInflater.from(this);
View mCustomView = mInflater.inflate(R.layout.actionbar_category_feed_list, null);
RelativeLayout rrBack = (RelativeLayout) mCustomView.findViewById(R.id.rr_back);
TextView title = (TextView) mCustomView.findViewById(R.id.txt_title);
title.setText("");
title.setTypeface(typeFaceMedium);
rrBack.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mTracker.send(new HitBuilders.EventBuilder().setCategory("" + userUsername).setAction("On Search Feed Screen").setLabel("Pressed Back Button").build());
Intent returnIntent = new Intent();
setResult(RESULT_CANCELED, returnIntent);
finish();
}
});
mActionBar.setCustomView(mCustomView);
mActionBar.setDisplayShowCustomEnabled(true);
**actionbar_category_feed_list.xml**
?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="@android:color/white" >
<RelativeLayout
android:id="@+id/rr_back"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" >
<ImageView
android:id="@+id/img_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:focusable="false"
android:src="@drawable/back_red" />
</RelativeLayout>
<com.converza.library.CustomTextView
android:id="@+id/txt_title"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/rr_back"
android:gravity="center_vertical"
android:paddingLeft="8dp"
android:text="@string/app_name" />
</RelativeLayout>
**At last in your fragment Activity use a OnactivityResult() for get a Returnintent from Activity.**
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == Const.FEEDDETAIL && resultCode == Activity.RESULT_OK) {
Log.e(tag, "DatashBoard Const.FEEDDETAIL RESULT_OK");
} else if (requestCode == Const.FEEDDETAIL && resultCode == Activity.RESULT_CANCELED) {
Log.e(tag, "DatashBoard Const.FEEDDETAIL RESULT_CANCELED");
}
}