TextView adding gradient AND shadow - DukeOrca/lock-screen Wiki

Original URL: https://github.com/DukeOrca/lock-screen/wiki/TextView-adding-gradient-AND-shadow

TextView adding gradient AND shadow

I had exactly the same problem. I managed to fix it by extending TextView and overriding onDraw method. Here is how it looks like

protected void onDraw(Canvas canvas) {
    // draw the shadow
    getPaint().setShadowLayer(1, 1, 1, 0xbf000000); // or whatever shadow you use

    // draw the gradient filled text
    getPaint().setShader(new LinearGradient(0, getHeight(), 0, 0, 0xffacacac, 0xffffffff, TileMode.CLAMP)); // or whatever gradient/shader you use

However this method probably won't work if you want to use colors with transparency in your gradient.