android - 如何以编程方式获得强调色?

标签 android android-xml android-styles

一个人如何以编程方式获取以下样式中的强调色设置?

    <item name="android:colorAccent">@color/material_green_500</item>

最佳答案

您可以通过以下方式从当前主题中获取它:

private int fetchAccentColor() {
    TypedValue typedValue = new TypedValue();

    TypedArray a = mContext.obtainStyledAttributes(typedValue.data, new int[] { R.attr.colorAccent });
    int color = a.getColor(0, 0);

    a.recycle();

    return color;
}

关于android - 如何以编程方式获得强调色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60922816/

相关文章:

android - ActionBarSherlock:更改 homeAsUpIndicator 不起作用

android - 如何在 XML 中指定 View 的宽度和高度的百分比?

android - Layout_anchor 等效于 ConstraintLayout

android - 如何在 XML 中定义一个特定 fragment 实例的样式/主题?

android - 如何在android中为TextView的文本设置样式或字体?

android - 如何设置 AlertDialog 项目高度?

android - 使用 Twilio for app to app VoIP 通话

java - (Eclipse) 无法显示标记/nullpointerException googlemaps api android

android - 将所有 android 测试(单元/集成/UI 测试)放入单个测试项目中是最佳做法吗?

android - 如何处理 Android M 中的不再询问复选框