14

I am developing an application and i set "android:textIsSelectable" for the TextViews.

But my material theme is not matching with the TextSelection appBar. Is there a way by which i can change the color of that appBar ??

Attached the Image Below Check it :-

enter image description here

Ashok Varma
  • 3,489
  • 3
  • 28
  • 43

2 Answers2

32

Assuming you use the appcompat-v7 library add these to your theme:¨

<!-- this makes sure the action mode is painted over not above the action bar -->
<item name="windowActionModeOverlay">true</item>
<item name="actionModeBackground">@drawable/myapp_action_mode_background</item>

Now I wasn't able to style the insides of the action mode (text color, icon colors) so hopefully you won't need to.

Note: If you don't use the support library prepend those style item names with android:. These will work above API 11+.

EDIT

For an action mode background with a stroke create a new drawable and update the reference. The drawable could look like this:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:top="-2dp" android:left="-2dp" android:right="-2dp">
    <shape android:shape="rectangle">
      <solid android:color="@color/primary_dark"/>
      <stroke android:color="@color/accent" android:width="2dp"/>
    </shape>
  </item>
</layer-list>
Eugen Pechanec
  • 37,669
  • 7
  • 103
  • 124
  • The color of text and menu items will most likely be the same as in your standard app bar. – Eugen Pechanec Feb 02 '15 at 13:45
  • Glad I could help, If you wanted to change the images or title style look through the [platform's themes.xml](https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/themes.xml) and search for "actionMode". – Eugen Pechanec Feb 02 '15 at 17:38
  • But after implementing this the whole Action Mode is in blue color which was set by me, is there anyway that i can get an yellow underline under the action Mode, as show in figure. i.e i need the action same as in the figure except the black need to be blue – Ashok Varma Feb 04 '15 at 16:00
  • and also is here anyway that i can add a share button in action mode ?? – Ashok Varma Feb 04 '15 at 16:01
  • See the updated answer. With the share button I can't help you :( – Eugen Pechanec Feb 04 '15 at 18:30
  • 1
    Works Perfectly thanks for the help. See if you can get any resources to add share button also. and once again thanks – Ashok Varma Feb 04 '15 at 18:39
  • when using translucent status bar that becomes black, is there a way to style status bar when action bar is shown? – Gianluca P. Mar 18 '15 at 14:30
  • You need to use [`ScrimInsetsFrameLayout`](https://github.com/google/iosched/blob/master/android/src/main/java/com/google/samples/apps/iosched/ui/widget/ScrimInsetsFrameLayout.java). Copy the class to your project and wrap your curent activity layout in it. You'll also need [`ScrimInsetsView` definition from `attrs.xml`](https://github.com/google/iosched/blob/master/android/src/main/res/values/attrs.xml). In your layout don't forget to set the `app:insetForeground` attribute to a color of your choice and `android:fitsSystemWindows` to `true`. – Eugen Pechanec Mar 18 '15 at 14:44
5

In your resources styles.xml: "android:textColorHighlight"

<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
   <item name="android:textColorHighlight">@color/yellow</item>
</style>
</resources>

You can put in whatever color you choose and whatever parent theme you are using.

  • 1
    I think the OP wanted to color the action mode, not the text selection. – Eugen Pechanec Feb 02 '15 at 13:35
  • But maybe if he didn't need to change the whole background but just the colored underline... Perhaps it inherits from `android:textColorHighlight` or at least `colorAccent`... – Eugen Pechanec Feb 02 '15 at 13:39
  • Yeah i know what you are talking about the highlight yellow color right. I set it by myself. Thanks for the reply – Ashok Varma Feb 02 '15 at 17:38