Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. import android.os.Bundle;
  2. import android.support.v7.app.ActionBar;
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.support.v7.view.ActionMode;
  5. import android.support.v7.widget.Toolbar;
  6. import android.view.Menu;
  7. import android.view.MenuItem;
  8.  
  9. public class RecyclerViewActivity extends AppCompatActivity {
  10. private ActionMode.Callback mActionModeCallback;
  11.  
  12. @Override
  13. protected void onCreate(Bundle savedInstanceState) {
  14. super.onCreate(savedInstanceState);
  15. setContentView(R.layout.activity_recycler_view);
  16.  
  17. initToolbar();
  18. initSupportActionMode();
  19.  
  20. //calling the method below causes the CAB to get a light theme
  21. //startSupportActionMode();
  22.  
  23. //calling the method below causes the CAB to get a dark theme
  24. //startSupportActionModeDelay();
  25. }
  26.  
  27. private void initToolbar() {
  28. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  29. setSupportActionBar(toolbar);
  30.  
  31. final ActionBar actionBar = getSupportActionBar();
  32.  
  33. if (actionBar != null) {
  34. actionBar.setDisplayHomeAsUpEnabled(true);
  35. actionBar.setHomeButtonEnabled(true);
  36. }
  37. }
  38. private void initSupportActionMode() {
  39. mActionModeCallback = new ActionMode.Callback() {
  40. @Override
  41. public boolean onCreateActionMode(ActionMode mode, Menu menu) {
  42. return true;
  43. }
  44.  
  45. @Override
  46. public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
  47. return false;
  48. }
  49.  
  50. @Override
  51. public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
  52. return false;
  53. }
  54.  
  55. @Override
  56. public void onDestroyActionMode(ActionMode mode) {
  57. }
  58. };
  59. }
  60.  
  61. private void startSupportActionMode() {
  62. startSupportActionMode(mActionModeCallback);
  63. }
  64.  
  65. private void startSupportActionModeDelay() {
  66. new Thread(new Runnable() {
  67. @Override
  68. public void run() {
  69. try {
  70. Thread.sleep(1000l);
  71. } catch (InterruptedException e) {
  72. e.printStackTrace();
  73. }
  74. runOnUiThread(new Runnable() {
  75. @Override
  76. public void run() {
  77. startSupportActionMode(mActionModeCallback);
  78. }
  79. });
  80. }
  81. }).start();
  82. }
  83. }
  84.  
  85. <android.support.design.widget.CoordinatorLayout
  86. xmlns:android="http://schemas.android.com/apk/res/android"
  87. xmlns:app="http://schemas.android.com/apk/res-auto"
  88. android:layout_width="match_parent"
  89. android:layout_height="match_parent"
  90. android:fitsSystemWindows="true">
  91.  
  92. <android.support.v7.widget.RecyclerView
  93. android:id="@+id/recycler_view"
  94. android:layout_width="match_parent"
  95. android:layout_height="wrap_content"
  96. android:clipToPadding="false"
  97. android:paddingTop="?attr/actionBarSize"/>
  98.  
  99. <android.support.design.widget.AppBarLayout
  100. android:layout_width="match_parent"
  101. android:layout_height="wrap_content">
  102. <android.support.v7.widget.Toolbar
  103. android:id="@+id/toolbar"
  104. android:layout_width="match_parent"
  105. android:layout_height="?attr/actionBarSize"
  106. android:elevation="4dp"
  107. android:background="?attr/colorPrimary"
  108. app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
  109. app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
  110. android:fitsSystemWindows="true">
  111.  
  112. </android.support.v7.widget.Toolbar>
  113. </android.support.design.widget.AppBarLayout>
  114.  
  115. </android.support.design.widget.CoordinatorLayout>
  116.  
  117. <resources>
  118. <!-- Base application theme. -->
  119. <style name="AppTheme" parent="BaseTheme" />
  120.  
  121. <style name="BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
  122. <item name="colorPrimary">@color/primary</item>
  123. <item name="colorPrimaryDark">@color/primary_dark</item>
  124. <item name="colorControlHighlight">@color/accent_translucent</item>
  125. <item name="colorAccent">@color/accent</item>
  126.  
  127. <item name="windowActionModeOverlay">true</item>
  128. </style>
  129.  
  130. <color name="primary">#00BCD4</color>
  131. <color name="primary_dark">#0097A7</color>
  132. <color name="accent">#FFEB3B</color>
  133. <color name="accent_translucent">#80FFEB3B</color>
  134. <color name="accent_bright">#FFF493</color>
  135. </resources>
  136.  
  137. <item name="actionBarPopupTheme">@style/ThemeOverlay.AppCompat.Light</item>
  138. <item name="actionBarTheme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement