@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); }
@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)); }
@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); }
@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); }
@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(); } }
@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); }
@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); }
@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); }
@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); }
@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 }
/** * 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(); }
/** * 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(); }
@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); }
@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(); } }
/** * 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)))); }
/** * Verify that the about activity can be started from main menu. */ @Test @MediumTest public void startAboutActivity() { CharSequence aboutTitle = InstrumentationRegistry.getTargetContext().getString(R.string.about, InstrumentationRegistry.getTargetContext().getString(R.string.app_name)); onView(withId(R.id.about)).perform(click()); onView(isAssignableFrom(Toolbar.class)) .check(matches(withToolbarTitle(is(aboutTitle)))); }
/** * Helper class that matches a given toolbar title. * * @param textMatcher The matcher to verify the toolbar title against * @return The matcher that will verify the toolbar title */ private static Matcher<Object> withToolbarTitle(final Matcher<CharSequence> textMatcher) { return new BoundedMatcher<Object, Toolbar>(Toolbar.class) { @Override public boolean matchesSafely(Toolbar toolbar) { return textMatcher.matches(toolbar.getTitle()); } @Override public void describeTo(Description description) { description.appendText("with toolbar title: "); textMatcher.describeTo(description); } }; }
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mToolbar = (Toolbar) view.findViewById(R.id.toolbar); mToolbar.setTitleTextColor(Color.BLACK); mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view); mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop(), mRecyclerView.getPaddingRight(), ViewUtility.getNavigationBarHeight()); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FragmentActivityWeakReference = new WeakReference < FragmentActivity > (this); setContentView(R.layout.main); String cmiyc = Tools.readString("cmiyc", null, this); if (cmiyc == null || cmiyc.isEmpty()) Tools.saveString("cmiyc", Tools.random4(), this); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setActionBar(toolbar); ViewPager viewPager = (ViewPager) findViewById(R.id.pager); viewPager.setAdapter(new TabsPagerAdapter(getFragmentManager())); viewPager.setOffscreenPageLimit(getTitles().length); TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout); tabLayout.setupWithViewPager(viewPager); mMasked = (TextView) findViewById(R.id.masked); if (!Tools.appId(getApplicationContext())) mMasked.setText(getString(R.string.masked)); mAbout = (TextView) findViewById(R.id.about); mAbout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent myIntent = new Intent(getApplicationContext(), AboutActivity.class); startActivity(myIntent); } }); check_writeexternalstorage(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_non_support_fragment_container); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setActionBar(toolbar); //we must always call BeRetained.onCreate() BeRetained.onCreate(this); boolean wasRestored = BeRetained.restore(this); if(wasRestored) { setTitle(R.string.retained_non_support); } else { setTitle(R.string.not_retained_non_support); } fillInitialValues(); FragmentManager fragmentManager = getFragmentManager(); RecyclerViewFragment recyclerViewFragment = (RecyclerViewFragment) fragmentManager.findFragmentById(R.id.container); if(recyclerViewFragment == null) { recyclerViewFragment = new RecyclerViewFragment(); fragmentManager.beginTransaction().add(R.id.container, recyclerViewFragment).commit(); } recyclerViewFragment.setItems(getItems()); }
private void initToolBar() { Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setActionBar(toolbar); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mDrawerLayout.openDrawer(mNavigationView); } }); }
protected void initToolbar() { final android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); final ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_toolbar); /* The Toolbar - introduced in API level 21 - is a generalization of the concept of * actiobar, and can be placed at any level of the view heirarchy. * * The Toolbar is more versatile and powerful. * * An Activity can designate a Toolbar as its action bar, by invoking setActionBar with * the Toolbar instance is its argument, as the following example illustrates. * * Sanjay Mishra * Author : "Wearable Android ..." 2015/ WILEY * * * */ toolbar = (Toolbar) findViewById ( R.id.toolbarActionbar) ; toolbar.setTitle( R.string.toolbar_title); toolbar.setLogo( R.mipmap.ic_launcher); setActionBar(toolbar); actionBar = getActionBar() ; }
/** * Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set up the layout from an XML file setContentView(R.layout.activity_task_list_and_editor); // Tell Android that R.id.toolbar is our ActionBar setActionBar((Toolbar) findViewById(R.id.toolbar)); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setActionBar(toolbar); mShortAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime); mEmptyView = (TextView) findViewById(R.id.empty); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_replaceable); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); TextView title = (TextView) toolbar.findViewById(android.R.id.title); setActionBar(toolbar); title.setText(toolbar.getTitle()); //noinspection ConstantConditions getActionBar().setTitle(null); Fragment f = new MainPreferenceFragment(); if (getIntent().getExtras() != null && getIntent().getExtras().containsKey(MainPreferenceFragment.EXTRA_SUBSCREEN_ID)) { Bundle args = new Bundle(); args.putInt(MainPreferenceFragment.EXTRA_SUBSCREEN_ID, getIntent().getExtras().getInt(MainPreferenceFragment.EXTRA_SUBSCREEN_ID)); f.setArguments(args); getActionBar().setDisplayHomeAsUpEnabled(true); title.setText(title.getText() + " - " + getString(R.string.pref_general_always_active_window)); } else if (getSharedPreferences(PREF_FILE_MAINACTIVITY, Context.MODE_PRIVATE) .getBoolean(PREF_SHOW_HSP_WARN, true)) { maybeShowNoHSPWarn(); } getFragmentManager().beginTransaction().replace(android.R.id.widget_frame, f).commit(); }