Java Code Examples for androidx.appcompat.app.ActionBar

The following examples show how to use androidx.appcompat.app.ActionBar. These examples are extracted from open source projects. 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 Project: arcusandroid   Source File: BaseFragment.java    License: Apache License 2.0 6 votes vote down vote up
private void toggleActionBarVisibility(boolean hide) {
    Activity activity = getActivity();
    if (activity == null || !(activity instanceof BaseActivity)) {
        return;
    }

    ActionBar actionBar = ((BaseActivity) activity).getSupportActionBar();
    if (actionBar != null) {
        if (hide) {
            actionBar.hide();
        }
        else {
            actionBar.show();
        }
    }
}
 
Example 2
Source Project: tindroid   Source File: AccSecurityFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    final AppCompatActivity activity = (AppCompatActivity) getActivity();
    if (activity == null) {
        return  null;
    }
    // Inflate the fragment layout
    View fragment = inflater.inflate(R.layout.fragment_acc_security, container, false);
    final ActionBar bar = activity.getSupportActionBar();
    if (bar != null) {
        bar.setDisplayHomeAsUpEnabled(true);
    }

    Toolbar toolbar = activity.findViewById(R.id.toolbar);
    toolbar.setTitle(R.string.security);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            activity.getSupportFragmentManager().popBackStack();
        }
    });

    return fragment;
}
 
Example 3
Source Project: talkback   Source File: BasePreferencesActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  ActionBar actionBar = getSupportActionBar();
  if (actionBar != null) {
    actionBar.setDisplayHomeAsUpEnabled(true);
  }

  // Create UI for the preferenceFragment created by the child class of BasePreferencesActivity.
  preferenceFragment = createPreferenceFragment();
  if (preferenceFragment != null) {
    getSupportFragmentManager()
        .beginTransaction()
        .replace(android.R.id.content, preferenceFragment)
        .commit();
  }
}
 
Example 4
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowHomeEnabled(true);
    }

    MessagePostParam postParam = getMessagePostParam();
    if (postParam.getAction().equals("new")) {
        setTitle(R.string.new_message);
    } else if (postParam.getAction().equals("reply")) {
        setTitle(R.string.reply_message);
    }

    Bundle bundle = new Bundle();
    bundle.putParcelable("param", postParam);
    Fragment fragment = new MessagePostFragment();
    fragment.setArguments(bundle);
    fragment.setHasOptionsMenu(true);
    getSupportFragmentManager().beginTransaction().replace(android.R.id.content, fragment).commit();

}
 
Example 5
Source Project: tindroid   Source File: LoginSettingsFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
    AppCompatActivity activity = (AppCompatActivity) getActivity();
    if (activity == null) {
        return;
    }

    setHasOptionsMenu(false);

    ActionBar bar = activity.getSupportActionBar();
    if (bar != null) {
        bar.setDisplayHomeAsUpEnabled(true);
        bar.setHomeButtonEnabled(true);
        bar.setTitle(R.string.settings);
    }

    addPreferencesFromResource(R.xml.login_preferences);

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
    onSharedPreferenceChanged(sharedPreferences, "pref_hostName");
    onSharedPreferenceChanged(sharedPreferences, "pref_useTLS");
    onSharedPreferenceChanged(sharedPreferences, "pref_wireTransport");
}
 
Example 6
Source Project: NewFastFrame   Source File: LockScreenActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void initData() {
    is_lock = true;
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.hide();
    }
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    mMusicPlayBean = MusicPlayerManager.getInstance().getMusicPlayBean();
    updateContent();
    addDisposable(Observable.interval(200, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread())
            .subscribe(aLong -> {
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("hh:mm-MM月dd日 E", Locale.CHINESE);
                String date[] = simpleDateFormat.format(new Date()).split("-");
                time.setText(date[0]);
                week.setText(date[1]);
                bottomLrc.seekTo(MusicPlayerManager.getInstance().getPosition(), false, false);
            }));
}
 
Example 7
Source Project: MovieGuide   Source File: MovieDetailsFragment.java    License: MIT License 6 votes vote down vote up
private void setToolbar() {
    collapsingToolbar.setContentScrimColor(ContextCompat.getColor(getContext(), R.color.colorPrimary));
    collapsingToolbar.setTitle(getString(R.string.movie_details));
    collapsingToolbar.setCollapsedTitleTextAppearance(R.style.CollapsedToolbar);
    collapsingToolbar.setExpandedTitleTextAppearance(R.style.ExpandedToolbar);
    collapsingToolbar.setTitleEnabled(true);

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

        ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
    } else {
        // Don't inflate. Tablet is in landscape mode.
    }
}
 
Example 8
Source Project: PersianDateRangePicker   Source File: AboutActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_about);
  Toolbar toolbar = findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);
  getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME |
    ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE);
  String versionName = "";
  try {
    versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
  } catch (PackageManager.NameNotFoundException e) {
    e.printStackTrace();
  }
  setTextWithLinks(R.id.text_application_info, getString(R.string.application_info_text, versionName));
  setTextWithLinks(R.id.text_developer_info, getString(R.string.developer_info_text));
  setTextWithLinks(R.id.text_libraries, getString(R.string.libraries_text));
  setTextWithLinks(R.id.text_license, getString(R.string.license_text));
}
 
Example 9
Source Project: DeviceConnect-Android   Source File: DevicePluginListActivity.java    License: MIT License 6 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setTitle(R.string.activity_devicepluginlist_title);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    if (savedInstanceState == null) {
        Fragment f = new DevicePluginListFragment();
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction t = fm.beginTransaction();
        t.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        t.add(android.R.id.content, f, "container");
        t.commit();
    }
}
 
Example 10
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String title = null;
    if (getArguments() != null) {
        title = getArguments().getString(ARG_TITLE);
        mText = getArguments().getString(ARG_TEXT);
    }

    // Update ActionBar
    AppCompatActivity activity = (AppCompatActivity) getActivity();
    if (activity != null) {
        ActionBar actionBar = activity.getSupportActionBar();
        if (actionBar != null) {
            actionBar.setTitle(title);
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
    }
}
 
Example 11
Source Project: tindroid   Source File: CredentialsFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    final LoginActivity parent = (LoginActivity) getActivity();
    if (parent == null) {
        return null;
    }

    setHasOptionsMenu(false);
    ActionBar bar = parent.getSupportActionBar();
    if (bar != null) {
        bar.setDisplayHomeAsUpEnabled(true);
    }

    View fragment = inflater.inflate(R.layout.fragment_validate, container, false);
    fragment.findViewById(R.id.confirm).setOnClickListener(this);
    fragment.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            parent.showFragment(LoginActivity.FRAGMENT_LOGIN);
        }
    });

    return fragment;
}
 
Example 12
Source Project: DevUtils   Source File: BaseToolbarActivity.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 初始化 ToolBar
 */
protected void initToolBar() {
    // = 处理 ActionBar =
    setSupportActionBar(vid_bt_toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        // 给左上角图标的左边加上一个返回的图标
        actionBar.setDisplayHomeAsUpEnabled(true);
        // 对应 ActionBar.DISPLAY_SHOW_TITLE
        actionBar.setDisplayShowTitleEnabled(false);
    }
    // 设置点击事件
    vid_bt_toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // 关闭页面
            finish();
        }
    });
}
 
Example 13
protected void initializeActionBar() {
  Toolbar toolbar = findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);

  ActionBar supportActionBar = getSupportActionBar();
  if (supportActionBar == null) throw new AssertionError();

  supportActionBar.setDisplayHomeAsUpEnabled(true);
  supportActionBar.setDisplayShowTitleEnabled(false);
}
 
Example 14
Source Project: braintree_android   Source File: CreateTransactionActivity.java    License: MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.create_transaction_activity);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    mLoadingSpinner = findViewById(R.id.loading_spinner);
    setTitle(R.string.processing_transaction);

    sendNonceToServer((PaymentMethodNonce) getIntent().getParcelableExtra(EXTRA_PAYMENT_METHOD_NONCE));
}
 
Example 15
Source Project: Jockey   Source File: BaseFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
protected ActionBar getActivitySupportActionBar() {
    Activity hostingActivity = getActivity();
    if (hostingActivity instanceof AppCompatActivity) {
        AppCompatActivity activity = (AppCompatActivity) hostingActivity;
        return activity.getSupportActionBar();
    } else {
        return null;
    }
}
 
Example 16
Source Project: WiFiAnalyzer   Source File: WiFiSwitchOn.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void applyToActionBar(@NonNull MainActivity mainActivity) {
    ActionBar actionBar = mainActivity.getSupportActionBar();
    if (actionBar != null) {
        int colorSelected = ContextCompat.getColor(mainActivity, R.color.selected);
        int colorNotSelected = ContextCompat.getColor(mainActivity, R.color.regular);
        Resources resources = mainActivity.getResources();
        String wiFiBand2 = resources.getString(WiFiBand.GHZ2.getTextResource());
        String wiFiBand5 = resources.getString(WiFiBand.GHZ5.getTextResource());
        WiFiBand wiFiBand = MainContext.INSTANCE.getSettings().getWiFiBand();
        String subtitle = makeSubtitle(WiFiBand.GHZ2.equals(wiFiBand), wiFiBand2, wiFiBand5, colorSelected, colorNotSelected);
        actionBar.setSubtitle(TextUtils.fromHtml(subtitle));
    }
}
 
Example 17
Source Project: DeviceConnect-Android   Source File: AccessLogActivity.java    License: MIT License 5 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mAccessLogProvider = new AccessLogProvider(getApplicationContext());

    setTitle(R.string.activity_settings_accesslog);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    if (savedInstanceState == null) {
        addFragment(DateListFragment.create(), false);
    }
}
 
Example 18
private void initViews() {
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    adapter = new MaterialAboutListAdapter(getViewTypeManager());
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(adapter);
    RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator();
    if (animator instanceof SimpleItemAnimator) {
        ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
    }
}
 
Example 19
/**
 * Per the navigation drawer design guidelines, updates the action bar to show the global app
 * 'context', rather than just what's in the current screen.
 */
private void showGlobalContextActionBar() {
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setTitle(R.string.app_name);
}
 
Example 20
private void toggleActionBar() {

        ActionBar actionBar = getSupportActionBar();

        if (actionBar != null) {
            if (actionBar.isShowing()) {
                actionBar.hide();
                hideUi();
            } else {
                showUi();
                actionBar.show();
            }
        }
    }
 
Example 21
private void setupActionBar()
{
    ViewGroup rootView = findViewById(R.id.action_bar_root); //id from appcompat
    if (rootView != null)
    {
        View view = getLayoutInflater().inflate(R.layout.activity_toolbar, rootView, false);
        rootView.addView(view, 0);

        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
    }

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null)
    {
        // Show the Up button in the action bar.
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle(R.string.action_app_settings);
    }

    // activate toolbar separator, if necessary
    {
        final int sepColor = CompatUtils.getThemeColorAttr(this, R.attr.colorToolBarSeparator);
        if (sepColor != Color.TRANSPARENT && findViewById(R.id.toolbar_separator) != null)
        {
            findViewById(R.id.toolbar_separator).setVisibility(View.VISIBLE);
        }
    }
}
 
Example 22
Source Project: science-journal   Source File: TextLabelDetailsFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  super.onCreateOptionsMenu(menu, inflater);
  inflater.inflate(R.menu.menu_text_label_details, menu);

  ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
  if (actionBar != null) {
    actionBar.setTitle(getActivity().getResources().getString(R.string.text_label_details_title));
  }
  super.onCreateOptionsMenu(menu, inflater);
}
 
Example 23
private void hide() {
    // Hide UI first
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.hide();
    }
    mControlsView.setVisibility(View.GONE);
    mVisible = false;

    // Schedule a runnable to remove the status and navigation bar after a delay
    mHideHandler.removeCallbacks(mShowPart2Runnable);
    mHideHandler.postDelayed(mHidePart2Runnable, UI_ANIMATION_DELAY);
}
 
Example 24
Source Project: HaoReader   Source File: DownloadActivity.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void setupActionBar() {
    AppCompat.setToolbarNavIconTint(toolbar, getResources().getColor(R.color.colorBarText));
    this.setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle(R.string.download_offline);
    }
}
 
Example 25
Source Project: science-journal   Source File: EditTriggerFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  inflater.inflate(R.menu.menu_edit_trigger, menu);

  ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
  actionBar.setDisplayHomeAsUpEnabled(true);
  if (isNewTrigger()) {
    actionBar.setHomeAsUpIndicator(R.drawable.ic_close_white_24dp);
    actionBar.setHomeActionContentDescription(android.R.string.cancel);
  }

  menu.findItem(R.id.action_save).setVisible(isNewTrigger());
  menu.findItem(R.id.action_save).setEnabled(!isSavingNewTrigger);

  SensorAppearance appearance =
      AppSingleton.getInstance(getActivity())
          .getSensorAppearanceProvider(appAccount)
          .getAppearance(sensorId);
  String triggerTitle =
      getString(
          isNewTrigger()
              ? R.string.title_fragment_add_trigger
              : R.string.title_fragment_edit_trigger);
  actionBar.setTitle(String.format(triggerTitle, appearance.getName(getActivity())));

  super.onCreateOptionsMenu(menu, inflater);
}
 
Example 26
Source Project: MasteringAndroidDataBinding   Source File: BaseActivity.java    License: MIT License 5 votes vote down vote up
@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);
    }
}
 
Example 27
protected void onSystemUiShown() {
    ActionBar ab = ((AppCompatActivity) mActivity).getSupportActionBar();
    if (ab != null) {
        ab.show();
    }

    mActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setIsShowing(true);
}
 
Example 28
Source Project: android   Source File: BaseActivity.java    License: MIT License 5 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();

    ActionBar bar = getSupportActionBar();
    if (null != bar) {
        bar.setDisplayHomeAsUpEnabled(true); // 设置返回按钮可见
        bar.setDisplayShowHomeEnabled(true); // 设置是否显示logo图标
        bar.setHomeButtonEnabled(true); // 设置左上角的图标可点击
    }
}
 
Example 29
Source Project: a   Source File: AboutFragment.java    License: GNU General Public License v3.0 5 votes vote down vote up
void setActionBarTitle(@StringRes int resId) {
    if (getActivity() != null) {
        ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
        if (actionBar != null)
            actionBar.setTitle(resId);
    }
}
 
Example 30
Source Project: a   Source File: SettingNestedFragment.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected void setActionBarTitle(CharSequence title) {
    if (getActivity() != null) {
        ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
        String t = StringUtils.nullToText(title);
        if (actionBar != null && !t.equals(actionBar.getTitle())) {
            actionBar.setTitle(t);
        }
    }
}