当前位置: 首页>>代码示例>>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;未经允许,请勿转载。