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


Java Toolbar類代碼示例

本文整理匯總了Java中android.widget.Toolbar的典型用法代碼示例。如果您正苦於以下問題:Java Toolbar類的具體用法?Java Toolbar怎麽用?Java Toolbar使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: onCreate

import android.widget.Toolbar; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

    toolbar = (Toolbar)findViewById(R.id.toolbarMainActivity);
    setUpActionBar();

  isListView = true;

  mStaggeredLayoutManager = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL);
  mRecyclerView = (RecyclerView)findViewById(R.id.list);

  mRecyclerView.setLayoutManager(mStaggeredLayoutManager);

  mAdapter = new TravelListAdapter(this);
  mRecyclerView.setAdapter(mAdapter);
  mAdapter.setOnItemClickListener(onItemClickListener);
}
 
開發者ID:anwarcse12028,項目名稱:Traveler-List,代碼行數:20,代碼來源:MainActivity.java

示例2: onCreate

import android.widget.Toolbar; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_guide);

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

    Resources resources = getResources();
    String[] titles = resources.getStringArray(R.array.fragment_guide);
    String[] messages = resources.getStringArray(R.array.fragment_guide_message);
    String[] messages2 = resources.getStringArray(R.array.fragment_guide_message2);
    String titleShowButton = resources.getString(R.string.fragment_guide_enjoy);

    ViewPager pager = findViewById(R.id.pager);
    pager.setAdapter(new GuidePagerAdapter(getFragmentManager(), titles, titleShowButton,
            messages, messages2));
}
 
開發者ID:brevent,項目名稱:Brevent,代碼行數:19,代碼來源:BreventGuide.java

示例3: onCreate

import android.widget.Toolbar; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // This is one half of configuring the action bar to have an up (back) arrow instead of
    // the usual hamburger menu. The other half is the override of configureActionBar().
    // I would like to put this line in that method but for some unknown reason that doesn't
    // work...we get no control at all in the hamburger position.
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    filter = getIntent().getStringExtra("filter");

    // Initialize the bookshelf label (empty in MainActivity) with the data
    // passed through our intent.
    View toolbar = findViewById(R.id.toolbar);
    final int background = Color.parseColor("#" + getIntent().getStringExtra("background"));
    toolbar.setBackgroundColor(background);
    TextView labelText = (TextView) findViewById(R.id.shelfName);
    labelText.setText(getIntent().getStringExtra("label"));
    ImageView bloomIcon = (ImageView)findViewById(R.id.bloom_icon);
    // replace the main bloom icon with the bookshelf one.
    bloomIcon.setImageResource(R.drawable.bookshelf);

    // The color chosen for the bookshelf may not contrast well with the default white
    // color of text and the back arrow and the default black color of the bookshelf icon.
    // Change them all to black or white, whichever gives better contrast.
    int forecolor = pickTextColorBasedOnBgColor(background, Color.WHITE, Color.BLACK);
    labelText.setTextColor(forecolor);
    // This bit of magic from https://stackoverflow.com/questions/26788464/how-to-change-color-of-the-back-arrow-in-the-new-material-theme
    // makes the the back arrow use the contrasting foreground color
    Drawable upArrow = ((android.support.v7.widget.Toolbar)toolbar).getNavigationIcon();
    upArrow.setColorFilter(forecolor, PorterDuff.Mode.SRC_ATOP);

    // And this bit, from https://stackoverflow.com/questions/1309629/how-to-change-colors-of-a-drawable-in-android,
    // switches the color of the bookshelf icon.
    bloomIcon.setColorFilter(forecolor);
}
 
開發者ID:BloomBooks,項目名稱:BloomReader,代碼行數:37,代碼來源:ShelfActivity.java

示例4: onCreate

import android.widget.Toolbar; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.activity_detail);

    postponeEnterTransition();

    TransitionSet transitions = new TransitionSet();
    Slide slide = new Slide(Gravity.BOTTOM);
    slide.setInterpolator(AnimationUtils.loadInterpolator(this,
            android.R.interpolator.linear_out_slow_in));
    slide.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime));
    transitions.addTransition(slide);
    transitions.addTransition(new Fade());
    getWindow().setEnterTransition(transitions);

    Intent intent = getIntent();
    sharedElementCallback = new DetailSharedElementEnterCallback(intent);
    setEnterSharedElementCallback(sharedElementCallback);
    initialItem = intent.getIntExtra(IntentUtil.SELECTED_ITEM_POSITION, 0);
    setUpViewPager(intent.<Photo>getParcelableArrayListExtra(IntentUtil.PHOTO));

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setNavigationOnClickListener(navigationOnClickListener);

    super.onCreate(savedInstanceState);
}
 
開發者ID:googlesamples,項目名稱:android-unsplash,代碼行數:27,代碼來源:DetailActivity.java

示例5: onCreate

import android.widget.Toolbar; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ViewGroup layout;
    if (SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        layout = (ViewGroup) getLayoutInflater().inflate(R.layout.activity_main, null);
        Toolbar toolbar = (Toolbar) layout.findViewById(R.id.toolbar);
        setActionBar(toolbar);
    } else {
        layout = (ViewGroup) getLayoutInflater().inflate(R.layout.activity_main_prelollipop, null);
    }
    mReactRootView = new ReactRootView(this);
    layout.addView(mReactRootView);

    setContentView(layout);

    if (SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(this)) {
        Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
        startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE);
    } else {
        startReactApplication();
    }
}
 
開發者ID:wix,項目名稱:react-native-notifications,代碼行數:25,代碼來源:MainActivity.java

示例6: onCreate

import android.widget.Toolbar; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_replaceable);

    setActionBar((Toolbar) findViewById(R.id.toolbar));
    //noinspection ConstantConditions
    getActionBar().setDisplayHomeAsUpEnabled(true);

    ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(
            R.layout.activity_log, (ViewGroup) findViewById(android.R.id.widget_frame), true);

    final WebView v = (WebView) findViewById(R.id.log);
    v.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
    v.getSettings().setUseWideViewPort(true);
    Logger.readLogcat(v);

}
 
開發者ID:woalk,項目名稱:HTCAuthorizer,代碼行數:19,代碼來源:LogActivity.java

示例7: onCreate

import android.widget.Toolbar; //導入依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ViewUnit.setCustomTheme(this);
    setContentView(R.layout.in_reply_to);

    Toolbar toolbar = (Toolbar) findViewById(R.id.in_reply_to_toolbar);
    ViewCompat.setElevation(toolbar, ViewUnit.getElevation(this, 2));

    setActionBar(toolbar);
    getActionBar().setTitle(getString(R.string.in_reply_to_label));
    getActionBar().setDisplayHomeAsUpEnabled(true);

    inReplyToFragment = (InReplyToFragment) getSupportFragmentManager().findFragmentById(R.id.in_reply_to_fragment);
}
 
開發者ID:mthli,項目名稱:Tweetin,代碼行數:17,代碼來源:InReplyToActivity.java

示例8: onCreate

import android.widget.Toolbar; //導入依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ViewUnit.setCustomTheme(this);
    setContentView(R.layout.search);

    Toolbar toolbar = (Toolbar) findViewById(R.id.search_toolbar);
    ViewCompat.setElevation(toolbar, ViewUnit.getElevation(this, 2));

    String keyWord = getIntent().getStringExtra(getString(R.string.search_intent_key_word));
    if (keyWord == null) {
        keyWord = getString(R.string.search_defauft_key_word);
    }

    setActionBar(toolbar);
    getActionBar().setTitle(keyWord);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    searchFragment = (SearchFragment) getSupportFragmentManager().findFragmentById(R.id.search_fragment);
}
 
開發者ID:mthli,項目名稱:Tweetin,代碼行數:22,代碼來源:SearchActivity.java

示例9: onCreate

import android.widget.Toolbar; //導入依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ViewUnit.setCustomTheme(this);
    setContentView(R.layout.picture);

    Toolbar toolbar = (Toolbar) findViewById(R.id.picture_toolbar);
    ViewCompat.setElevation(toolbar, ViewUnit.getElevation(this, 2));

    setActionBar(toolbar);
    getActionBar().setTitle(getString(R.string.picture_label));
    getActionBar().setDisplayHomeAsUpEnabled(true);

    tweet = (new TweetUnit(this)).getTweetFromIntent(getIntent());

    pictureFragment = (PictureFragment) getSupportFragmentManager().findFragmentById(R.id.picture_fragment);
}
 
開發者ID:mthli,項目名稱:Tweetin,代碼行數:19,代碼來源:PictureActivity.java

示例10: onCreate

import android.widget.Toolbar; //導入依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    FragmentManager fm = getSupportFragmentManager();
    Fragment fragment = fm.findFragmentById(R.id.fragment_container);

    if (fragment == null) {
        fragment = createFragment();
        fm.beginTransaction().add(R.id.fragment_container, fragment)
                .commit();
    }

    // Integrate Toolbar so sliding drawer can go over toolbar
    android.support.v7.widget.Toolbar mtoolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.my_toolbar);
    setSupportActionBar(mtoolbar);

    setTitle(R.string.app_name);
    super.setupDrawer(); // Needs to be called after setContentView
    // Disabled by request. Turns into BACK button
    //super.enableDrawerIndicator(); // Enable drawer toggle button
}
 
開發者ID:kamegami13,項目名稱:MonsterHunter4UDatabase,代碼行數:25,代碼來源:GenericActivity.java

示例11: setActionBar

import android.widget.Toolbar; //導入依賴的package包/類
/**
 * Set a {@link android.widget.Toolbar Toolbar} to act as the {@link ActionBar} for this
 * Activity window.
 *
 * <p>When set to a non-null value the {@link #getActionBar()} method will return
 * an {@link ActionBar} object that can be used to control the given toolbar as if it were
 * a traditional window decor action bar. The toolbar's menu will be populated with the
 * Activity's options menu and the navigation button will be wired through the standard
 * {@link android.R.id#home home} menu select action.</p>
 *
 * <p>In order to use a Toolbar within the Activity's window content the application
 * must not request the window feature {@link Window#FEATURE_ACTION_BAR FEATURE_ACTION_BAR}.</p>
 *
 * @param toolbar Toolbar to set as the Activity's action bar, or {@code null} to clear it
 */
public void setActionBar(@Nullable Toolbar toolbar) {
    final ActionBar ab = getActionBar();
    if (ab instanceof WindowDecorActionBar) {
        throw new IllegalStateException("This Activity already has an action bar supplied " +
                "by the window decor. Do not request Window.FEATURE_ACTION_BAR and set " +
                "android:windowActionBar to false in your theme to use a Toolbar instead.");
    }

    // If we reach here then we're setting a new action bar
    // First clear out the MenuInflater to make sure that it is valid for the new Action Bar
    mMenuInflater = null;

    // If we have an action bar currently, destroy it
    if (ab != null) {
        ab.onDestroy();
    }

    if (toolbar != null) {
        final ToolbarActionBar tbab = new ToolbarActionBar(toolbar, getTitle(), this);
        mActionBar = tbab;
        mWindow.setCallback(tbab.getWrappedWindowCallback());
    } else {
        mActionBar = null;
        // Re-set the original window callback since we may have already set a Toolbar wrapper
        mWindow.setCallback(this);
    }

    invalidateOptionsMenu();
}
 
開發者ID:JessYanCoding,項目名稱:ProgressManager,代碼行數:45,代碼來源:a.java

示例12: ActionBarDrawerToggle

import android.widget.Toolbar; //導入依賴的package包/類
/**
 * In the future, we can make this constructor public if we want to let developers customize
 * the
 * animation.
 */
ActionBarDrawerToggle(Activity activity, Toolbar toolbar, DrawerLayout drawerLayout,
                      DrawerArrowDrawable slider, @StringRes int openDrawerContentDescRes,
                      @StringRes int closeDrawerContentDescRes) {
  if (toolbar != null) {
    mActivityImpl = new ToolbarCompatDelegate(toolbar);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        if (mDrawerIndicatorEnabled) {
          toggle();
        } else if (mToolbarNavigationClickListener != null) {
          mToolbarNavigationClickListener.onClick(v);
        }
      }
    });
  } else if (activity instanceof DelegateProvider) { // Allow the Activity to provide an impl
    mActivityImpl = ((DelegateProvider) activity).getDrawerToggleDelegate();
  } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
    mActivityImpl = new JellybeanMr2Delegate(activity);
  } /*else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    mActivityImpl = new IcsDelegate(activity);
  } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    mActivityImpl = new HoneycombDelegate(activity);
  }*/ else {
    mActivityImpl = new DummyDelegate(activity);
  }

  mDrawerLayout = drawerLayout;
  mOpenDrawerContentDescRes = openDrawerContentDescRes;
  mCloseDrawerContentDescRes = closeDrawerContentDescRes;
  if (slider == null) {
    mSlider = new DrawerArrowDrawable(mActivityImpl.getActionBarThemedContext());
  } else {
    mSlider = slider;
  }

  mHomeAsUpIndicator = getThemeUpIndicator();
}
 
開發者ID:commonsguy,項目名稱:cwac-crossport,代碼行數:44,代碼來源:ActionBarDrawerToggle.java

示例13: onCreate

import android.widget.Toolbar; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    setActionBar((Toolbar) findViewById(R.id.toolbar));
    mEditBody = (EditText) findViewById(R.id.body);
    findViewById(R.id.share).setOnClickListener(mOnClickListener);
}
 
開發者ID:sdrausty,項目名稱:buildAPKsSamples,代碼行數:9,代碼來源:MainActivity.java

示例14: onCreate

import android.widget.Toolbar; //導入依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    setActionBar((Toolbar) findViewById(R.id.toolbar));
    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayShowTitleEnabled(false);
    }

    if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_MIDI)) {
        setupMidi();
    }
}
 
開發者ID:sdrausty,項目名稱:buildAPKsSamples,代碼行數:15,代碼來源:MainActivity.java

示例15: startSettingsActivity

import android.widget.Toolbar; //導入依賴的package包/類
/**
 * Verify that the settings activity can be started from main menu.
 */
@Test
@MediumTest
public void startSettingsActivity() {
    CharSequence settingsTitle =
            InstrumentationRegistry.getTargetContext().getString(R.string.settings);

    onView(withId(R.id.settings)).perform(click());
    onView(isAssignableFrom(Toolbar.class))
            .check(matches(withToolbarTitle(is(settingsTitle))));
}
 
開發者ID:FelixWohlfrom,項目名稱:Presenter-Client-Android,代碼行數:14,代碼來源:MainActivityTest.java


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