【问题标题】:How to get a Text's shadow color programatically in android?如何在android中以编程方式获取文本阴影颜色?
【发布时间】:2016-06-09 07:09:30
【问题描述】:

我知道如何在 android 中为 editText 设置阴影:

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

但我的问题是:如何在 android 中以编程方式获取文本的阴影颜色?

*

当然我必须补充一点,我的最低 API 级别是 15。

*

感谢所有能回答这个问题的人

【问题讨论】:

  • 发布一些代码。你是如何设置阴影的?

标签: java android colors android-edittext shadow


【解决方案1】:

API 级别 >= 16 可以使用以下方法:

int shadowColor = editText.getShadowColor();

对于 API 级别 ,似乎没有直接的方法来获取 EditText 的阴影颜色。

在这种情况下我会怎么做:

扩展EditText,覆盖setShadowLayer()并编写自己的方法来获取阴影颜色:

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;
    }
}

然后在您的代码/布局中使用CustomEditText 而不是EditText 并调用getShadowLayerColor() 来获取阴影的颜色。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    • 2016-04-15
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多