@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowTitleEnabled(true); actionBar.setDisplayUseLogoEnabled(false); } }
protected ActionBar readyActionBarToCustomView () { ActionBar ab = getSupportActionBar(); ab.setDisplayShowHomeEnabled(false); ab.setDisplayShowTitleEnabled(false); ab.setDisplayShowCustomEnabled(true); return ab; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_fragment_container); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); }
public static void setupActionBar(Activity activity, boolean isLightBar, int bgColorRes, int bgColorRes2, int titleRes, Toolbar toolbar) { Window window = activity.getWindow(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { window.setStatusBarColor(activity.getResources().getColor(bgColorRes2)); if (!isLightBar) { toolbar.setTitleTextColor(activity.getResources().getColor(R.color.white)); } } else { window.setStatusBarColor(activity.getResources().getColor(bgColorRes, null)); if (isLightBar) { window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); } else { toolbar.setTitleTextColor(activity.getResources().getColor(R.color.white)); window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); } } toolbar.setTitle(activity.getString(titleRes)); ((AppCompatActivity) activity).setSupportActionBar(toolbar); ActionBar actionBar = ((AppCompatActivity) activity).getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayShowHomeEnabled(true); } }
/** * Set the icon and on click listener for the back or up button in the app bar. * * @param icon The drawable used for the back or up button. * @param onClickListener The click listener for the back or up button. */ public void setNavigationClickListener(@Nullable Drawable icon, @Nullable View.OnClickListener onClickListener) { mToolbar.setNavigationIcon(icon); setSupportActionBar(mToolbar); final ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayShowHomeEnabled(true); actionBar.setHomeButtonEnabled(onClickListener != null); } mToolbar.setNavigationOnClickListener(onClickListener); }
setSupportActionBar(toolbar); getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
/**************************used method*******************************************/ protected ActionBar supportActionBar(Toolbar toolbar) { setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowHomeEnabled(true); } mToolbar.setNavigationOnClickListener( (v) -> finish() ); return actionBar; } }
actionBar.setDisplayShowHomeEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true);
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.about_page_main_activity); toolbar = findViewById(R.id.toolbar); ImageView icon = findViewById(R.id.icon); slogan = findViewById(R.id.slogan); version = findViewById(R.id.version); collapsingToolbar = findViewById(R.id.collapsing_toolbar); headerContentLayout = findViewById(R.id.header_content_layout); onTitleViewCreated(collapsingToolbar); onCreateHeader(icon, slogan, version); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowHomeEnabled(true); } onApplyPresetAttrs(); recyclerView = findViewById(R.id.list); }