Override theme color for touch highlight, scroll hinting
Asked Answered
N

6

9

I am trying to substitute and override the default touch highlight color of the theme for the corporate ones.

I have successfully done it for the actionbar buttons by using actionBarItemBackground on my theme properties, but I am looking at an application-wide change where every pressed element in buttons, actionbar, drawer or menus defaults to my color instead of the Holo blue. I have tried properties like colorPressedHighlight. colorFocusedHighlight but none worked.

I would also like to change the color of the scroll end hinting, the little gradients on the sides of a scrollable element when it has reached one end and the uses is still attempting to scroll.

Given the high volume of incorrect answers, let me restate again. I know what a selector is, I know how to use it, I have explicitly stated that I have overriden the theme with several different subproperties but none does what I asked for. I am looking for the property to change both the default touch highlight for all elements, and the color for the scroll cache hinting, again for all elements.

Nonlegal answered 10/1, 2014 at 12:9 Comment(1)
I cannot believe there's not one actual, definitive answer. This is such a basic thing to want to do, and any solution appears to be so convoluted, obscured or obfuscated you'd think google is going out of their way to make it difficult. Unbelievable. The android view layer sucks. Period.Tanta
N
3

I found the answer here: https://mcmap.net/q/506406/-changing-the-color-of-over-scroll-in-scrollview-in-android

The name of the component is not scroll hinting but overscroll.

Nonlegal answered 28/3, 2014 at 21:11 Comment(0)
F
3

To change the end-of-scroll hint you can try this library for a fancy solution, or just the code below for a quick solution(code source and explanation):

static void brandGlowEffect(Context context, int brandColor) {
    int glowDrawableId = context.getResources().getIdentifier("overscroll_glow", "drawable", "android");
    Drawable androidGlow = context.getResources().getDrawable(glowDrawableId);
    androidGlow.setColorFilter(brandColor, PorterDuff.Mode.MULTIPLY);
}

Note that both of these are a bit hacky fundamentally as they works on platform drawable resources that are not guaranteed to stay the same between Android releases, though the plus note is that these resources have not been renamed from 1.0 to KitKat.

Fichte answered 19/1, 2014 at 9:47 Comment(0)
N
3

I found the answer here: https://mcmap.net/q/506406/-changing-the-color-of-over-scroll-in-scrollview-in-android

The name of the component is not scroll hinting but overscroll.

Nonlegal answered 28/3, 2014 at 21:11 Comment(0)
A
0

What you want to do is add a custom_color.xml file to your apps drawables folder. You can name it what ever you want and it might look similar to

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
    <shape>
        <gradient
            android:startColor="#004F81"
            android:endColor="#004F81"
            android:angle="270" />
        <stroke
            android:width="3dp"
            android:color="#004F81" />
        <corners
            android:radius="3dp" />          
    </shape>
</item>
<item android:state_focused="true" >
    <shape>
        <gradient
            android:endColor="#004F81"
            android:startColor="#004F81"
            android:angle="270" />
        <stroke
            android:width="3dp"
            android:color="#004F81" />
        <corners
            android:radius="3dp" />         
    </shape>
</item>
<item>        
    <shape>
        <gradient
            android:endColor="#43AFE8"
            android:startColor="#43AFE8"
            android:angle="270" />
        <stroke
            android:width="1dp"
            android:color="#43AFE8" />
        <corners
            android:radius="6dp" />
        <padding
            android:left="2dp"
            android:top="2dp"
            android:right="2dp"
            android:bottom="2dp" />
    </shape>
</item>
</selector>

Then in all of your layout xml files just set the back round of each element to your custom back round

<Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/custom_color"
        android:textColor="#FFFFFF"
        android:text="Button" />

I am currently implementing this and it works quite well.

Annmarie answered 15/1, 2014 at 18:19 Comment(1)
While this is a feasible solution it detracts from maintainability, a lot of work for very little. There's a theming property where you can make all buttons inherit this style but I was looking for something more generic.Nonlegal
G
0

You can read here about the State List.
Basically what you'd want to do is create a selector that overrides the color with your color and then create a theme that is a "child" of the default holo theme and change the elements you want to change the color for with your selector. This will give you a more application wide solution. Read about the Style and Themes here.

Grounds answered 19/1, 2014 at 12:45 Comment(1)
Given that you haven't read the OP or any of the other answers: which of the properties is the one overriding the elements that I ask. Nobody has given that answer yet.Nonlegal
E
0

I guess the right answer would be "No, there isn't a theme attribute you can override in your own themes that will magically change the highlight color across your app's Activities and Fragments". Or, in my case "No, there isn't a theme attribute you can reference to get your current theme's highlight color".

As to "Why?", I guess it's because Google itself doesn't use a theme attribute across all of the standard UI widgets (TextView, EditText, Button, ListView, etc.) because they rely on PNG drawables (9 patches) and not only on state lists.

Great question, though.

Eanore answered 14/7, 2014 at 10:50 Comment(1)
There is one coming in L, apparently.Nonlegal
A
-1

You can set up your styles here: http://android-holo-colors.com/

Then download, integrate and set it in your app.

Annulose answered 10/1, 2014 at 12:32 Comment(9)
I already tried it but it doesn't cover scroll hinting or the drawer.Nonlegal
For that scroll issue, you can define your custome scroll. Like this:Annulose
i would edit it, but a workmate came in. Here the code: For that scroll issue, you can define your custome scroll. Like this:<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="schemas.android.com/apk/res/android" > <gradient android:angle="45" android:endColor="#FF3401" android:centerColor="#ff5c33" android:startColor="#FF3401" /><corners android:radius="8dp" /></shape>Annulose
Same as the guy below, I require WHERE TO embed it to apply it theme-wide, not the code to create a color drawable.Nonlegal
There is good case for automated tools, but I'd rather know where and why does the change come from, because I can't reproduce it manually.Nonlegal
you must define your own theme. Just like the Holo Color Website i've posted. In This you set the Attributes (just like in my comment) for your scrollview. And the complete theme you can set in the androidmanifest.xmlAnnulose
If you reread the OP that's what I did, but I don't know which attributes map to the customised scroll and buttons.Nonlegal
Please take a look at this: android.googlesource.com/platform/frameworks/base/+/refs/heads/…Annulose
>. I have tried properties like colorPressedHighlight. colorFocusedHighlight but none worked. I have already tried them, failed, and they are poorly documented.Nonlegal

© 2022 - 2024 — McMap. All rights reserved.