Created
September 23, 2014 22:19
-
-
Save frhan/c18cb86052405f10c0d9 to your computer and use it in GitHub Desktop.
custom action bar for android
This file contains 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
private void setCustomActionbar() | |
{ | |
actionBar.setLogo(null); // forgot why this one but it helped | |
View homeIcon = findViewById(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? | |
android.R.id.home : android.support.v7.appcompat.R.id.home); | |
((View) homeIcon.getParent()).setVisibility(View.GONE); | |
((View) homeIcon).setVisibility(View.GONE); | |
actionBar.setDisplayShowTitleEnabled(false); | |
ActionBar.LayoutParams params = new ActionBar.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); | |
View customNav = LayoutInflater.from(this).inflate(R.layout.custom_action_bar, null); // layout which contains your button. | |
actionBar.setCustomView(customNav,params); | |
ImageButton ibtn = (ImageButton) customNav.findViewById(R.id.ibtn_log_out); | |
ibtn.setOnClickListener(new OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
onClickLogOut(); | |
} | |
}); | |
actionBar.setDisplayShowHomeEnabled(true); | |
actionBar.setDisplayShowTitleEnabled(false); | |
actionBar.setDisplayShowCustomEnabled(true); | |
actionBar.setLogo(new ColorDrawable(Color.TRANSPARENT)); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment