本文整理汇总了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);
}
示例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));
}
示例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);
}
示例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);
}
示例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();
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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
}
示例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();
}
示例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();
}
示例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);
}
示例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();
}
}
示例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))));
}