Hossein Seifi Hossein Seifi - 5 months ago 18
Java Question

How to get a Text's shadow color programatically in android?

I know how to set shadow for an editText in android:

editText.setShadowLayer(float radius, float dx, float dy, int color);


But my question is : How to get a Text's shadow color programatically in android?

*


Of course I have to add that my minimum API level is 15.


*

Thanks to everybody who can answer this question

Answer

You can use the following method for API level >= 16:

int shadowColor = editText.getShadowColor();

For API level < 16, there seem to be no direct way to get the shadow color of an EditText.

What i would do in this case:

Extend EditText, override setShadowLayer() and write your own method to get the shadow color:

public class CustomEditText extends EditText {
    int shadowColor = 0;

    public CustomEditText(Context context) {
        super(context);
    }

    public CustomEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void setShadowLayer(float radius, float dx, float dy, int color) {
        shadowColor = color;
        super.setShadowLayer(radius, dx, dy, color);
    }

    public int getShadowLayerColor() {
        return shadowColor;
    }
}

Then use CustomEditText instead of EditText in your code/layout and call getShadowLayerColor() to get the color of the shadow.

Comments