Java Code Examples for android.support.v7.app.ActionBar.setDisplayShowCustomEnabled()

The following are Jave code examples for showing how to use setDisplayShowCustomEnabled() of the android.support.v7.app.ActionBar class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: rx-twitter-stream-android   File: StreamActivity.java   View Source Code Vote up 5 votes
private void handleMenuSearch() {
    ActionBar supportActionBar = getSupportActionBar();

    if (isSearchOpened) {
        disableSearch(supportActionBar);
    } else {

        supportActionBar.setDisplayShowCustomEnabled(true);
        supportActionBar.setCustomView(R.layout.search_bar);
        supportActionBar.setDisplayShowTitleEnabled(false);

        termsSearch = (EditText) supportActionBar.getCustomView().findViewById(R.id.terms_search);

        termsSearch.setOnEditorActionListener((view, id, event) -> {
            if (id == EditorInfo.IME_ACTION_SEARCH) {
                doSearch(termsSearch.getText().toString());
                disableSearch(supportActionBar);
                return true;
            }
            return false;
        });

        termsSearch.requestFocus();

        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

        mSearchAction.setIcon(getResources().getDrawable(R.mipmap.ic_clear_white_24dp, null));

        isSearchOpened = true;
    }
}
 
Example 2
Project: rx-twitter-stream-android   File: StreamActivity.java   View Source Code Vote up 5 votes
private void disableSearch(ActionBar action) {
    action.setDisplayShowCustomEnabled(false);
    action.setDisplayShowTitleEnabled(true);

    termsSearch.clearFocus();
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

    mSearchAction.setIcon(getResources().getDrawable(R.mipmap.ic_search_white_24dp, null));

    isSearchOpened = false;
}
 
Example 3
Project: Nird2   File: BriarActivity.java   View Source Code Vote up 5 votes
/**
 * This should be called after the content view has been added in onCreate()
 *
 * @param ownLayout true if the custom toolbar brings its own layout
 * @return the Toolbar object or null if content view did not contain one
 */
@Nullable
protected Toolbar setUpCustomToolbar(boolean ownLayout) {
	// Custom Toolbar
	Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
	setSupportActionBar(toolbar);
	ActionBar ab = getSupportActionBar();
	if (ab != null) {
		ab.setDisplayShowHomeEnabled(true);
		ab.setDisplayHomeAsUpEnabled(true);
		ab.setDisplayShowCustomEnabled(ownLayout);
		ab.setDisplayShowTitleEnabled(!ownLayout);
	}
	return toolbar;
}
 
Example 4
Project: Nird2   File: BriarActivity.java   View Source Code Vote up 5 votes
/**
 * This should be called after the content view has been added in onCreate()
 *
 * @param ownLayout true if the custom toolbar brings its own layout
 * @return the Toolbar object or null if content view did not contain one
 */
@Nullable
protected Toolbar setUpCustomToolbar(boolean ownLayout) {
	// Custom Toolbar
	Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
	setSupportActionBar(toolbar);
	ActionBar ab = getSupportActionBar();
	if (ab != null) {
		ab.setDisplayShowHomeEnabled(true);
		ab.setDisplayHomeAsUpEnabled(true);
		ab.setDisplayShowCustomEnabled(ownLayout);
		ab.setDisplayShowTitleEnabled(!ownLayout);
	}
	return toolbar;
}
 
Example 5
Project: SimpleRssReader   File: MainActivity.java   View Source Code Vote up 5 votes
@SuppressWarnings("ConstantConditions")
private void hideSearchView() {
    final ActionBar actionBar = getSupportActionBar();
    final android.support.v7.widget.Toolbar toolbar =
            (android.support.v7.widget.Toolbar) actionBar.getCustomView().getParent();

    final EditText searchEditText = actionBar.getCustomView()
            .findViewById(R.id.ActivityMainSearchEditText);

    if (!TextUtils.isEmpty(searchEditText.getText().toString())) {
        searchEditText.setText(null);

        SoftInputUtils.forceShowSoftInput(this, toolbar);
    } else {
        final List<Integer> ids = Arrays.asList(R.attr.colorPrimary,
                R.attr.colorPrimaryDark);

        TypedValueUtils.resolveResourceIds(MainActivity.this, ids);

        setActionBarColor(ids.get(0));
        setStatusBarColor(ids.get(1));

        toggleSystemUiVisibility(true);

        toolbar.setContentInsetsAbsolute(mActionBarInsets[0], mActionBarInsets[1]);

        SoftInputUtils.dismissSoftInput(this, toolbar);

        actionBar.setCustomView(null);
        actionBar.setDisplayShowCustomEnabled(false);

        actionBar.setDisplayShowTitleEnabled(true);

        invalidateOptionsMenu();
    }
}
 
Example 6
Project: IslamicLibraryAndroid   File: SettingsActivity.java   View Source Code Vote up 4 votes
@Override
    protected void onCreate(Bundle savedInstanceState) {
        ((IslamicLibraryApplication) getApplication()).refreshLocale(this, false);
        super.onCreate(savedInstanceState);

        // Enable if you use AppCompat 24.1.x.
//        Fixes.updateLayoutInflaterFactory(getLayoutInflater());

        setContentView(R.layout.activity_settings);

        mReplaceFragmentStrategy = new PreferenceScreenNavigationStrategy
                .ReplaceFragment(this,
                R.anim.abc_fade_in,
                R.anim.abc_fade_out,
                R.anim.abc_fade_in,
                R.anim.abc_fade_out);

        if (savedInstanceState == null) {
            mSettingsFragment = SettingsFragment.newInstance(null);
            getSupportFragmentManager().beginTransaction().add(R.id.content, mSettingsFragment, "Settings").commit();
        } else {
            mSettingsFragment = (SettingsFragment) getSupportFragmentManager().findFragmentByTag("Settings");
        }

        getSupportFragmentManager().addOnBackStackChangedListener(this);

        mToolbar = findViewById(R.id.toolbar);
        setSupportActionBar(mToolbar);
        ActionBar ab = getSupportActionBar();


        // Cross-fading title setup.
        mTitle = getTitle();

        mTitleSwitcher = new TextSwitcher(mToolbar.getContext());
        mTitleSwitcher.setFactory(() -> {
            TextView tv = new AppCompatTextView(mToolbar.getContext());
            TextViewCompat.setTextAppearance(tv, R.style.TextAppearance_AppCompat_Widget_ActionBar_Title);
            return tv;
        });
        mTitleSwitcher.setCurrentText(mTitle);
        if (ab != null) {
            ab.setDisplayHomeAsUpEnabled(true);
            ab.setCustomView(mTitleSwitcher);
            ab.setDisplayShowCustomEnabled(true);
            ab.setDisplayShowTitleEnabled(false);
        }


        // Add to hierarchy before accessing layout params.
        int margin = Util.dpToPxOffset(this, 16);
        ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mTitleSwitcher.getLayoutParams();
        lp.leftMargin = margin;
        lp.rightMargin = margin;

        mTitleSwitcher.setInAnimation(this, R.anim.abc_fade_in);
        mTitleSwitcher.setOutAnimation(this, R.anim.abc_fade_out);
    }