androidx.appcompat.app.ActionBar Java Examples

The following examples show how to use androidx.appcompat.app.ActionBar. 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: BaseToolbarActivity.java    From DevUtils with 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 #2
Source File: BaseFragment.java    From arcusandroid with 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 #3
Source File: AccSecurityFragment.java    From tindroid with 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 #4
Source File: CredentialsFragment.java    From tindroid with 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 #5
Source File: BasePreferencesActivity.java    From talkback with 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 #6
Source File: CommonHelpFragment.java    From Bluefruit_LE_Connect_Android_V2 with MIT License 6 votes vote down vote up
@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 #7
Source File: DevicePluginListActivity.java    From DeviceConnect-Android with 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 #8
Source File: AboutActivity.java    From PersianDateRangePicker with 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 File: MovieDetailsFragment.java    From MovieGuide with 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 #10
Source File: LockScreenActivity.java    From NewFastFrame with 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 #11
Source File: LoginSettingsFragment.java    From tindroid with 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 #12
Source File: MessagePostActivity.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 6 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(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 #13
Source File: GDPRViewManager.java    From GDPRDialog with Apache License 2.0 5 votes vote down vote up
public void initActionBar(Activity activity, ActionBar supportActionBar) {
    if (supportActionBar != null)
        if (mSetup.getCustomTexts().hasTitle())
            supportActionBar.setTitle(mSetup.getCustomTexts().getTitle(activity));
        else
            supportActionBar.setTitle(R.string.gdpr_dialog_title);
}
 
Example #14
Source File: SelectEntriesActivity.java    From Aegis with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_select_entries);

    ActionBar bar = getSupportActionBar();
    bar.setHomeAsUpIndicator(R.drawable.ic_close);
    bar.setDisplayHomeAsUpEnabled(true);

    _adapter = new ImportEntriesAdapter();
    RecyclerView entriesView = findViewById(R.id.list_entries);
    entriesView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            onScroll(dx, dy);
        }
    });

    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    entriesView.setLayoutManager(layoutManager);
    entriesView.setAdapter(_adapter);
    entriesView.setNestedScrollingEnabled(false);

    Intent intent = getIntent();
    List<ImportEntry> entries = (ArrayList<ImportEntry>) intent.getSerializableExtra("entries");
    List<DatabaseImporterEntryException> errors = (ArrayList<DatabaseImporterEntryException>) intent.getSerializableExtra("errors");

    for (ImportEntry entry : entries) {
        _adapter.addEntry(entry);
    }

    if (errors.size() > 0) {
        showErrorDialog(errors);
    }

    FloatingActionButton fabMenu = findViewById(R.id.fab);
    fabMenu.setOnClickListener(v -> returnSelectedEntries());
    _fabScrollHelper = new FabScrollHelper(fabMenu);
}
 
Example #15
Source File: WiFiSwitchOnTest.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
@Before
public void setUp() {
    mainActivity = RobolectricUtil.INSTANCE.getActivity();

    actionBar = mock(ActionBar.class);
    optionMenu = mock(OptionMenu.class);
    menu = mock(Menu.class);
    menuItem = mock(MenuItem.class);

    fixture = new WiFiSwitchOn();
}
 
Example #16
Source File: ReadBookActivity.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void setupActionBar() {
    AppCompat.setToolbarNavIconTint(toolbar, getResources().getColor(R.color.colorBarText));
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
}
 
Example #17
Source File: ListStoreAppsFragment.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
public void setupToolbar(View view) {
  Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
  ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
  ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
  actionBar.setDisplayHomeAsUpEnabled(true);
  toolbar.setTitle(R.string.list_store_apps_fragment_title);
  actionBar.setTitle(toolbar.getTitle());
}
 
Example #18
Source File: PreferenceActivity.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Hides the navigation icon of the activity's toolbar, respectively sets it to the previous
 * icon.
 */
private void hideToolbarNavigationIcon() {
    if (!displayHomeAsUp) {
        ActionBar actionBar = getSupportActionBar();

        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(false);
            actionBar.setHomeButtonEnabled(false);
        }
    }
}
 
Example #19
Source File: SettingActivity.java    From HaoReader with 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.setting);
    }
}
 
Example #20
Source File: PreferencesActivity.java    From TowerCollector with Mozilla Public License 2.0 5 votes vote down vote up
private void setupActionBar() {
    Toolbar toolbar = findViewById(R.id.preferences_toolbar);
    toolbar.setPopupTheme(MyApplication.getCurrentPopupTheme());
    setSupportActionBar(toolbar);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
}
 
Example #21
Source File: BaseActivity.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 5 votes vote down vote up
@Deprecated
public void setupActionBar(Toolbar toolbar) {
    if (toolbar != null && getSupportActionBar() == null) {
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setHomeButtonEnabled(true);
        }
    }
}
 
Example #22
Source File: HostDemoSettingFragment.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@Override
public void onAttach(final Context context) {
    super.onAttach(context);
    Activity activity = getActivity();
    if (activity != null) {
        ActionBar actionBar = ((AppCompatActivity) activity).getSupportActionBar();
        if (actionBar != null) {
            actionBar.setTitle(getString(R.string.demo_page_settings_title));
        }
    }
}
 
Example #23
Source File: AppendToNoteActivity.java    From nextcloud-notes with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Intent receivedIntent = getIntent();
    receivedText = receivedIntent.getStringExtra(Intent.EXTRA_TEXT);
    @Nullable final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        getSupportActionBar().setTitle(R.string.append_to_note);
    } else {
        Log.e(TAG, "SupportActionBar is null. Expected toolbar to be present to set a title.");
    }
    binding.activityNotesListView.toolbar.setSubtitle(receivedText);
}
 
Example #24
Source File: TagSettingActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_setting);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
}
 
Example #25
Source File: UpdateExperimentFragment.java    From science-journal with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  inflater.inflate(R.menu.menu_update_experiment, menu);

  ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
  actionBar.setHomeAsUpIndicator(R.drawable.ic_close_white_24dp);
  actionBar.setHomeActionContentDescription(android.R.string.cancel);

  super.onCreateOptionsMenu(menu, inflater);
}
 
Example #26
Source File: HomeActivity.java    From SmsCode with GNU General Public License v3.0 5 votes vote down vote up
private void refreshActionBar(String title) {
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle(title);
        actionBar.setHomeButtonEnabled(true);
        if (mCurrentFragment instanceof SettingsFragment) {
            actionBar.setDisplayHomeAsUpEnabled(false);
        } else {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
    }
}
 
Example #27
Source File: ManageUserFragment.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
private void setupToolbar() {
  if (isEditProfile) {
    toolbar.setTitle(getString(R.string.edit_profile_title));
  } else {
    toolbar.setTitle(R.string.create_user_title);
  }
  ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
  final ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
  actionBar.setDisplayHomeAsUpEnabled(false);
  actionBar.setTitle(toolbar.getTitle());
}
 
Example #28
Source File: QRCodeScanActivity.java    From a with GNU General Public License v3.0 5 votes vote down vote up
private void setupActionBar() {
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle(R.string.scan_qr_code);
    }
}
 
Example #29
Source File: ConversationActivity.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
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 #30
Source File: StartConversationActivity.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
private void configureHomeButton() {
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar == null) {
        return;
    }
    boolean openConversations = !createdByViewIntent && !xmppConnectionService.isConversationsListEmpty(null);
    actionBar.setDisplayHomeAsUpEnabled(openConversations);
    actionBar.setDisplayHomeAsUpEnabled(openConversations);

}