Created
February 18, 2014 19:58
-
-
Save danmikita/9078752 to your computer and use it in GitHub Desktop.
Custom Action Bar Layout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
android:gravity="fill_horizontal" | |
android:orientation="horizontal"> | |
<Button | |
android:id="@+id/action_bar_button_cancel" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
android:layout_weight="1" | |
android:background="@drawable/selector_white_button" | |
android:text="@string/cancel" /> | |
<LinearLayout | |
android:background="@drawable/divider" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center_vertical" /> | |
<Button | |
android:id="@+id/action_bar_button_submit" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
android:layout_weight="1" | |
android:background="@drawable/selector_white_button" | |
android:text="@string/submit_caps" /> | |
</LinearLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
View view = inflater.inflate(R.layout.fragment_sample, container, false /* attachToRoot */); | |
ActionBar actionBar = ((ActionBarActivity) getActivity()).getSupportActionBar(); | |
setHasOptionsMenu(true); | |
actionBar.setDisplayShowHomeEnabled(false); | |
actionBar.setDisplayShowTitleEnabled(false); | |
View actionBarView = inflater.inflate(R.layout.custom_actionbar_layout, null); | |
actionBar.setCustomView(actionBarView, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); | |
actionBar.setDisplayShowCustomEnabled(true); | |
Button btnCancel = (Button) actionBarView.findViewById(R.id.action_bar_button_cancel); | |
btnCancel.setOnClickListener(new OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
getActivity().finish(); | |
} | |
}); | |
Button btnSubmit = (Button) actionBarView.findViewById(R.id.action_bar_button_submit); | |
btnSubmit.setOnClickListener(new OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
// Your custom logic | |
} | |
}); | |
return view; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment