當前位置: 首頁>>代碼示例>>Java>>正文


Java ActionBar.setCustomView方法代碼示例

本文整理匯總了Java中android.support.v7.app.ActionBar.setCustomView方法的典型用法代碼示例。如果您正苦於以下問題:Java ActionBar.setCustomView方法的具體用法?Java ActionBar.setCustomView怎麽用?Java ActionBar.setCustomView使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v7.app.ActionBar的用法示例。


在下文中一共展示了ActionBar.setCustomView方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onResume

import android.support.v7.app.ActionBar; //導入方法依賴的package包/類
@Override
protected void onResume() {
    super.onResume();

    ActionBar actionBar = getSupportActionBar();

    if (actionBar != null && !resumed) {

        // add the custom view to the action bar
        actionBar.setCustomView(R.layout.search_actionbar);

        searchField = (EditText) actionBar.getCustomView().findViewById(R.id.searchField);
        searchField.addTextChangedListener(this);

        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
        actionBar.setDisplayHomeAsUpEnabled(true);

        resumed = true;
    }
}
 
開發者ID:AbyxBelgium,項目名稱:Loyalty,代碼行數:21,代碼來源:SearchResultsActivity.java

示例2: onCreate

import android.support.v7.app.ActionBar; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mAdapter = new CheesesAdapter();

    final ListView listView = (ListView) findViewById(android.R.id.list);
    listView.setAdapter(mAdapter);

    final ActionBar actionBar = getSupportActionBar();
    actionBar.setCustomView(R.layout.search_view);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

    final EditText editText = (EditText) actionBar.getCustomView();
    editText.addTextChangedListener(mTextWatcher);
    editText.requestFocus();
}
 
開發者ID:cyrilmottier,項目名稱:QueryHighlighter,代碼行數:19,代碼來源:MainActivity.java

示例3: onCreate

import android.support.v7.app.ActionBar; //導入方法依賴的package包/類
/**
 * On creation of the activity, set up the action bar title
 * and check that the user has granted permissions for reading
 * external storage.
 * @param savedInstanceState - Bundle
 */
@Override
final protected void onCreate(final Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  setContentView(R.layout.activity_main);
  mLayout = findViewById(R.id.coordinator_layout);

  final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  if (toolbar != null){
    final ActionBar actionBar = (this).getSupportActionBar();
    if (actionBar != null){

      actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
      actionBar.setTitle(R.string.title);
      actionBar.setCustomView(R.layout.logged_in_user);
    }
    toolbar.setNavigationIcon(null);
  }

}
 
開發者ID:Esri,項目名稱:mapbook-android,代碼行數:27,代碼來源:MapbookActivity.java

示例4: handleMenuSearch

import android.support.v7.app.ActionBar; //導入方法依賴的package包/類
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;
    }
}
 
開發者ID:rsetkus,項目名稱:rx-twitter-stream-android,代碼行數:33,代碼來源:StreamActivity.java

示例5: hideSearchView

import android.support.v7.app.ActionBar; //導入方法依賴的package包/類
@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();
    }
}
 
開發者ID:Applications-Development,項目名稱:SimpleRssReader,代碼行數:37,代碼來源:MainActivity.java

示例6: onCreate

import android.support.v7.app.ActionBar; //導入方法依賴的package包/類
@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);
    }
 
開發者ID:fekracomputers,項目名稱:IslamicLibraryAndroid,代碼行數:59,代碼來源:SettingsActivity.java


注:本文中的android.support.v7.app.ActionBar.setCustomView方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。