Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.os.Bundle;
- import android.support.v7.app.ActionBar;
- import android.support.v7.app.AppCompatActivity;
- import android.support.v7.view.ActionMode;
- import android.support.v7.widget.Toolbar;
- import android.view.Menu;
- import android.view.MenuItem;
- public class RecyclerViewActivity extends AppCompatActivity {
- private ActionMode.Callback mActionModeCallback;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_recycler_view);
- initToolbar();
- initSupportActionMode();
- //calling the method below causes the CAB to get a light theme
- //startSupportActionMode();
- //calling the method below causes the CAB to get a dark theme
- //startSupportActionModeDelay();
- }
- private void initToolbar() {
- Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
- setSupportActionBar(toolbar);
- final ActionBar actionBar = getSupportActionBar();
- if (actionBar != null) {
- actionBar.setDisplayHomeAsUpEnabled(true);
- actionBar.setHomeButtonEnabled(true);
- }
- }
- private void initSupportActionMode() {
- mActionModeCallback = new ActionMode.Callback() {
- @Override
- public boolean onCreateActionMode(ActionMode mode, Menu menu) {
- return true;
- }
- @Override
- public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
- return false;
- }
- @Override
- public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
- return false;
- }
- @Override
- public void onDestroyActionMode(ActionMode mode) {
- }
- };
- }
- private void startSupportActionMode() {
- startSupportActionMode(mActionModeCallback);
- }
- private void startSupportActionModeDelay() {
- new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- Thread.sleep(1000l);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- startSupportActionMode(mActionModeCallback);
- }
- });
- }
- }).start();
- }
- }
- <android.support.design.widget.CoordinatorLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:fitsSystemWindows="true">
- <android.support.v7.widget.RecyclerView
- android:id="@+id/recycler_view"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:clipToPadding="false"
- android:paddingTop="?attr/actionBarSize"/>
- <android.support.design.widget.AppBarLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
- <android.support.v7.widget.Toolbar
- android:id="@+id/toolbar"
- android:layout_width="match_parent"
- android:layout_height="?attr/actionBarSize"
- android:elevation="4dp"
- android:background="?attr/colorPrimary"
- app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
- app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
- android:fitsSystemWindows="true">
- </android.support.v7.widget.Toolbar>
- </android.support.design.widget.AppBarLayout>
- </android.support.design.widget.CoordinatorLayout>
- <resources>
- <!-- Base application theme. -->
- <style name="AppTheme" parent="BaseTheme" />
- <style name="BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
- <item name="colorPrimary">@color/primary</item>
- <item name="colorPrimaryDark">@color/primary_dark</item>
- <item name="colorControlHighlight">@color/accent_translucent</item>
- <item name="colorAccent">@color/accent</item>
- <item name="windowActionModeOverlay">true</item>
- </style>
- <color name="primary">#00BCD4</color>
- <color name="primary_dark">#0097A7</color>
- <color name="accent">#FFEB3B</color>
- <color name="accent_translucent">#80FFEB3B</color>
- <color name="accent_bright">#FFF493</color>
- </resources>
- <item name="actionBarPopupTheme">@style/ThemeOverlay.AppCompat.Light</item>
- <item name="actionBarTheme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement