Java Code Examples for androidx.appcompat.app.AppCompatActivity#setSupportActionBar()

The following examples show how to use androidx.appcompat.app.AppCompatActivity#setSupportActionBar() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainFragment.java    From AndroidFastScroll with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    AppCompatActivity activity = (AppCompatActivity) requireActivity();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        View decorView = activity.getWindow().getDecorView();
        decorView.setSystemUiVisibility(decorView.getSystemUiVisibility()
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
    }

    activity.setSupportActionBar(mToolbar);

    if (savedInstanceState == null) {
        setNavigationCheckedItem(R.id.recycler_view_list);
    }
    mNavigationView.setNavigationItemSelectedListener(this::onNavigationItemSelected);

    AppBarLayoutLiftOnScrollHack.hack(mAppBarLayout, R.id.scrolling_view);
}
 
Example 2
Source File: ToolbarHelper.java    From CloudReader with Apache License 2.0 6 votes vote down vote up
/**
 * 将Toolbar高度填充到状态栏
 */
public static void initFullBar(Toolbar toolbar, AppCompatActivity activity) {
    ViewGroup.LayoutParams params = toolbar.getLayoutParams();
    params.height = DensityUtil.getStatusHeight(activity) + getSystemActionBarSize(activity);
    toolbar.setLayoutParams(params);
    toolbar.setPadding(
            toolbar.getLeft(),
            toolbar.getTop() + DensityUtil.getStatusHeight(activity),
            toolbar.getRight(),
            toolbar.getBottom()
    );
    activity.setSupportActionBar(toolbar);
    ActionBar actionBar = activity.getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);
}
 
Example 3
Source File: ExtendedFabBehaviorDemoFragment.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public View onCreateDemoView(
    LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
  View root =
      layoutInflater.inflate(getExtendedFabContent(), viewGroup, false /* attachToRoot */);

  Toolbar toolbar = root.findViewById(R.id.toolbar);
  AppCompatActivity activity = (AppCompatActivity) getActivity();
  activity.setSupportActionBar(toolbar);

  List<ExtendedFloatingActionButton> extendedFabs =
      DemoUtils.findViewsWithType(root, ExtendedFloatingActionButton.class);
  for (ExtendedFloatingActionButton extendedFab : extendedFabs) {
    extendedFab.setOnClickListener(
        v ->
            Snackbar.make(
                    v, R.string.cat_extended_fab_clicked, Snackbar.LENGTH_SHORT)
                .show());
  }

  return root;
}
 
Example 4
Source File: DemoFragment.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private void initDemoActionBar() {
  if (shouldShowDefaultDemoActionBar()) {
    AppCompatActivity activity = (AppCompatActivity) getActivity();
    activity.setSupportActionBar(toolbar);
    setDemoActionBarTitle(activity.getSupportActionBar());
  } else {
    toolbar.setVisibility(View.GONE);
  }
}
 
Example 5
Source File: UploadWidgetFragment.java    From cloudinary_android with MIT License 5 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    AppCompatActivity activity = (AppCompatActivity) getActivity();
    if (activity != null) {
        Toolbar toolbar = getActivity().findViewById(R.id.toolbar);
        activity.setSupportActionBar(toolbar);
        ActionBar actionBar = activity.getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setDisplayShowTitleEnabled(false);
        }
    }
}
 
Example 6
Source File: NavigationDrawerFragment.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
private ActionBar setupActionBar() {
    AppCompatActivity activity = (AppCompatActivity) getActivity();
    activity.setSupportActionBar(toolbar);
    final ActionBar actionBar = activity.getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);
    return actionBar;
}
 
Example 7
Source File: TopAppBarCollapsingDemoFragment.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateDemoView(
    LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
  View view =
      layoutInflater.inflate(R.layout.cat_topappbar_collapsing_fragment, viewGroup, false);

  Toolbar toolbar = view.findViewById(R.id.toolbar);
  AppCompatActivity activity = (AppCompatActivity) getActivity();
  activity.setSupportActionBar(toolbar);

  return view;
}
 
Example 8
Source File: TopAppBarScrollingDemoFragment.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateDemoView(
    LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
  View view = layoutInflater.inflate(R.layout.cat_topappbar_scrolling_fragment, viewGroup, false);

  Toolbar toolbar = view.findViewById(R.id.toolbar);
  AppCompatActivity activity = (AppCompatActivity) getActivity();
  activity.setSupportActionBar(toolbar);

  return view;
}
 
Example 9
Source File: BaseFragment.java    From Jockey with Apache License 2.0 5 votes vote down vote up
protected void setActivitySupportActionBar(Toolbar toolbar) {
    Activity hostingActivity = getActivity();
    if (hostingActivity instanceof AppCompatActivity) {
        AppCompatActivity activity = (AppCompatActivity) hostingActivity;
        activity.setSupportActionBar(toolbar);
    } else {
        Timber.w("Hosting activity is not an AppCompatActivity. Toolbar will not be bound.");
    }
}
 
Example 10
Source File: TopAppBarCollapsingMultilineDemoFragment.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateDemoView(
    LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
  View view =
      layoutInflater.inflate(
          R.layout.cat_topappbar_collapsing_multiline_fragment, viewGroup, false);

  Toolbar toolbar = view.findViewById(R.id.toolbar);
  AppCompatActivity activity = (AppCompatActivity) getActivity();
  activity.setSupportActionBar(toolbar);

  return view;
}
 
Example 11
Source File: Utility.java    From Instagram-Profile-Downloader with MIT License 5 votes vote down vote up
public static void setToolbar(AppCompatActivity activity, Toolbar toolbar, String title) {
    toolbar.setTitle(title);
    toolbar.setTitleTextColor(activity.getResources().getColor(R.color.white));
    activity.setSupportActionBar(toolbar);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        Objects.requireNonNull(activity.getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
    }
}
 
Example 12
Source File: AppViewFragment.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
public void setupToolbar() {

    toolbar.setTitle("");

    final AppCompatActivity activity = (AppCompatActivity) getActivity();
    activity.setSupportActionBar(toolbar);
    actionBar = activity.getSupportActionBar();
    if (actionBar != null) {
      actionBar.setDisplayHomeAsUpEnabled(true);
      actionBar.setTitle(toolbar.getTitle());
    }
  }
 
Example 13
Source File: AppCoinsInfoFragment.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
private void setupToolbar() {
  toolbar.setTitle(R.string.appc_title_about_appcoins);
  toolbar.setTitleTextColor(Color.WHITE);
  toolbar.setSubtitleTextColor(Color.WHITE);
  AppCompatActivity appCompatActivity = ((AppCompatActivity) getActivity());
  appCompatActivity.setSupportActionBar(toolbar);
  ActionBar actionBar = appCompatActivity.getSupportActionBar();
  if (actionBar != null) {
    actionBar.setDisplayHomeAsUpEnabled(true);
  }
}
 
Example 14
Source File: MoreBundleFragment.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
  super.onViewCreated(view, savedInstanceState);
  getFragmentComponent(savedInstanceState).inject(this);
  if (savedInstanceState != null) {
    if (savedInstanceState.containsKey(MORE_LIST_STATE_KEY)) {
      listState = savedInstanceState.getParcelable(MORE_LIST_STATE_KEY);
      savedInstanceState.putParcelable(MORE_LIST_STATE_KEY, null);
    }
  }
  bundlesList = view.findViewById(R.id.more_bundles_list);
  toolbarElement = view.findViewById(R.id.action_bar);
  errorView = view.findViewById(R.id.error_view);
  progressBar = view.findViewById(R.id.progress_bar);
  swipeRefreshLayout = view.findViewById(R.id.more_refresh_layout);
  toolbar = view.findViewById(R.id.toolbar);
  adapter = new BundlesAdapter(new ArrayList<>(), new ProgressBundle(), new ErrorHomeBundle(),
      oneDecimalFormatter, uiEventsListener,
      new AdsBundlesViewHolderFactory(uiEventsListener, adClickedEvents, oneDecimalFormatter,
          marketName, false), captionBackgroundPainter, marketName, themeAttributeProvider);
  layoutManager = new LinearLayoutManager(getContext());
  bundlesList.setLayoutManager(layoutManager);
  bundlesList.setAdapter(adapter);
  AppCompatActivity appCompatActivity = ((AppCompatActivity) getActivity());
  if (getArguments().getBoolean(StoreTabGridRecyclerFragment.BundleCons.TOOLBAR, true)) {
    appCompatActivity.setSupportActionBar(toolbar);
    ActionBar actionBar = appCompatActivity.getSupportActionBar();
    if (actionBar != null) {
      actionBar.setDisplayHomeAsUpEnabled(true);
    }
  } else {
    toolbarElement.setVisibility(GONE);
  }
  attachPresenter(presenter);
}
 
Example 15
Source File: CropRotateFragment.java    From cloudinary_android with MIT License 5 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    AppCompatActivity activity = (AppCompatActivity) getActivity();
    if (activity != null) {
        Toolbar toolbar = getActivity().findViewById(R.id.cropRotateToolbar);
        activity.setSupportActionBar(toolbar);
        ActionBar actionBar = activity.getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setDisplayShowTitleEnabled(false);
        }
    }
}
 
Example 16
Source File: MyAccountFragment.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
private void setupToolbar() {
  toolbar.setTitle(R.string.my_account_title_my_account);

  final AppCompatActivity activity = (AppCompatActivity) getActivity();
  activity.setSupportActionBar(toolbar);
  ActionBar actionBar = activity.getSupportActionBar();
  if (actionBar != null) {
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setTitle(toolbar.getTitle());
  }
  toolbar.setNavigationOnClickListener(v -> getActivity().onBackPressed());
}
 
Example 17
Source File: SettingsFragment.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
  super.onViewCreated(view, savedInstanceState);
  context = getContext();
  toolbar = view.findViewById(R.id.toolbar);

  final AppCompatActivity parentActivity = (AppCompatActivity) getActivity();
  if (toolbar != null) {
    parentActivity.setSupportActionBar(toolbar);

    toolbar.setTitle(R.string.settings_title_settings);
    toolbar.setNavigationOnClickListener(v -> getActivity().onBackPressed());

    ActionBar supportActionBar = parentActivity.getSupportActionBar();
    if (supportActionBar != null) {
      supportActionBar.setDisplayHomeAsUpEnabled(true);
    }
  }
  setAdultContentViews();
  excludedUpdates = findPreference(EXCLUDED_UPDATES_PREFERENCE_KEY);
  sendFeedback = findPreference(SEND_FEEDBACK_PREFERENCE_KEY);
  setGDPR();
  setupAppTheme();
  deleteAccount = findPreference(DELETE_ACCOUNT);
  socialCampaignNotifications =
      (SwitchPreferenceCompat) findPreference(CAMPAIGN_SOCIAL_NOTIFICATIONS_PREFERENCE_VIEW_KEY);
  fileMaxCachePreferenceView = findPreference(MAX_FILE_CACHE);
  setupClickHandlers();
}
 
Example 18
Source File: ProductGridFragment.java    From material-components-android-codelabs with Apache License 2.0 5 votes vote down vote up
private void setUpToolbar(View view) {
    Toolbar toolbar = view.findViewById(R.id.app_bar);
    AppCompatActivity activity = (AppCompatActivity) getActivity();
    if (activity != null) {
        activity.setSupportActionBar(toolbar);
    }

    toolbar.setNavigationOnClickListener(new NavigationIconClickListener(
            getContext(),
            view.findViewById(R.id.product_grid),
            new AccelerateDecelerateInterpolator(),
            getContext().getResources().getDrawable(R.drawable.shr_branded_menu), // Menu open icon
            getContext().getResources().getDrawable(R.drawable.shr_close_menu))); // Menu close icon
}
 
Example 19
Source File: DemoLandingFragment.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("RestrictTo")
@Nullable
@Override
public View onCreateView(
    LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
  View view =
      layoutInflater.inflate(
          R.layout.cat_demo_landing_fragment, viewGroup, false /* attachToRoot */);

  Bundle arguments = getArguments();
  if (arguments != null) {
    String transitionName = arguments.getString(FeatureDemoUtils.ARG_TRANSITION_NAME);
    ViewCompat.setTransitionName(view, transitionName);
  }

  Toolbar toolbar = view.findViewById(R.id.toolbar);

  AppCompatActivity activity = (AppCompatActivity) getActivity();
  activity.setSupportActionBar(toolbar);
  activity.getSupportActionBar().setTitle(getTitleResId());
  activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);

  Context toolbarContext = toolbar.getContext();
  TypedArray a =
      toolbarContext
          .getTheme()
          .obtainStyledAttributes(new int[] {R.attr.colorControlNormal, R.attr.colorAccent});
  colorControlNormal =
      MaterialResources.getColorStateList(toolbarContext, a, 0).getDefaultColor();
  colorAccent = a.getColor(1, 0);

  TextView descriptionTextView = view.findViewById(R.id.cat_demo_landing_description);
  ViewGroup mainDemoContainer = view.findViewById(R.id.cat_demo_landing_main_demo_container);
  ViewGroup additionalDemosSection =
      view.findViewById(R.id.cat_demo_landing_additional_demos_section);
  ViewGroup additionalDemosContainer =
      view.findViewById(R.id.cat_demo_landing_additional_demos_container);

  // Links should be added whether or not the feature is restricted.
  addLinks(layoutInflater, view);

  // If this fragments demos is restricted, due to conditions set by the subclass, exit early
  // without showing any demos and just show the restricted message.
  if (isRestricted()) {
    descriptionTextView.setText(getRestrictedMessageId());
    mainDemoContainer.setVisibility(View.GONE);
    additionalDemosSection.setVisibility(View.GONE);
    return view;
  }

  descriptionTextView.setText(getDescriptionResId());
  addDemoView(layoutInflater, mainDemoContainer, getMainDemo(), false);
  List<Demo> additionalDemos = getAdditionalDemos();
  for (Demo additionalDemo : additionalDemos) {
    addDemoView(layoutInflater, additionalDemosContainer, additionalDemo, true);
  }
  additionalDemosSection.setVisibility(additionalDemos.isEmpty() ? View.GONE : View.VISIBLE);

  DemoUtils.addBottomSpaceInsetsIfNeeded((ViewGroup) view, viewGroup);
  return view;
}
 
Example 20
Source File: MusicBrowserFragment.java    From Jockey with Apache License 2.0 4 votes vote down vote up
private void setupToolbar(Toolbar toolbar) {
    if (getActivity() instanceof AppCompatActivity) {
        AppCompatActivity activity = (AppCompatActivity) getActivity();
        activity.setSupportActionBar(toolbar);
    }
}